Any fix of Scaled Geometry Collections result in a potential memory leak in Physics?

This question was created in reference to: [Scaled Geometry Collections result in a potential memory leak in [Content removed]

<br/>

We have lots of scaled GCs in our project, which we have also narrowed down to the ChaosUpdate related memory.

But the issue in the referenced post is not public. So we want more information on the issue.

[Attachment Removed]

Hi there,

I’ve made the ticket public now (which was the issue), and I’ve spoken with the team about it. From a quick investigation, it looks like a reference counting issue which is stopping the deletion on unload.

You can follow the resolution to this via the public bug tracker.

All the best and thank you for raising this!

Geoff

[Attachment Removed]

This is pretty much what I’d expect we will end up doing as a fix as well. Essentially we are throwing away the knowledge that this object is temporarily constructed so doesn’t need persistent ownership. As you say the fix is then having the function with that knowledge make it an rvalue and pass that in so it uses the non pointer constructor and gets deleted as expected.

Timelines wise we know the fix, so I’d expect it to be within a short timescale.

Best

Geoff

[Attachment Removed]

Great stuff, let us know if you run into any further issues :slight_smile:

[Attachment Removed]

Hi,

We did some investigation as well, and found it is caused by

DeepCopyGeometryWithScale constructs the TImplicitObjectScaled with raw ptr and here make the object persistent, and there seems no where to delete it.

	TImplicitObjectScaled(TConcrete* Object, const FVec3& Scale, FReal InMargin = 0)
		: FImplicitObjectScaled(EImplicitObject::HasBoundingBox, Object->GetType())
		, MObject(Object)
	{
		// Transient if raw pointer not already stored in a ref counted one
		if(Object && (Object->GetRefCount() == 1))
		{
			Object->MakePersistent();
		}
		InitScaledImplicit(Scale, FRealSingle(InMargin));
	}

We tried to fix it by constructing a RefCountPtr instead of raw ptr just like how it was done before UE5.4, then MakePersistent won’t get called anymore and the memory leak issue is gone.

But we are not sure are there any other impact and the original reason to pass by raw ptr?

	FImplicitObjectPtr FConvex::DeepCopyGeometryWithScale(const FVec3& Scale) const
	{
		TRefCountPtr<FConvex> Copy(new FConvex(*this));
		return FImplicitObjectPtr(new TImplicitObjectScaled<FConvex>(Copy, Scale));
		// return FImplicitObjectPtr(new TImplicitObjectScaled<FConvex>(new FConvex(*this), Scale));
	}

Is there any target fix or temporary workaround?

[Attachment Removed]

Thanks Geoff, I saw the fix yesterday, I will merge the fix after 5.8.3 was released. :slight_smile:

[Attachment Removed]