Description

The leaking variable is UInstancedStaticMeshComponent::InstanceDataBuffers.
The memory block is passed to InitPerInstanceRenderData() via InstanceDataBuffers.Release(). But the function doesn't manage the passed memory block.

Following workaround works.
 

void UInstancedStaticMeshComponent::OnPostLoadPerInstanceData()
{
	if (!HasAnyFlags(RF_ClassDefaultObject|RF_ArchetypeObject))
	{
		// create PerInstanceRenderData and pass InstanceDataBuffers ownership to it
#if 0
		InitPerInstanceRenderData(true, InstanceDataBuffers.Release());
#else
		InitPerInstanceRenderData(true, InstanceDataBuffers.Get());
#endif
	}

	// release InstanceDataBuffers
	InstanceDataBuffers.Reset();
void UHierarchicalInstancedStaticMeshComponent::OnPostLoadPerInstanceData()
{
...
			if (!bForceTreeBuild)
			{
				// Create PerInstanceRenderData either from current data or pre-built instance buffer
#if 0
				InitPerInstanceRenderData(true, InstanceDataBuffers.Release());
#else
				InitPerInstanceRenderData(true, InstanceDataBuffers.Get());
#endif
				NumBuiltRenderInstances = PerInstanceRenderData->InstanceBuffer_GameThread->GetNumInstances();
				InstanceCountToRender = NumBuiltInstances;
			}

			// If any of the data is out of sync, build the tree now!
			BuildTreeIfOutdated(bAsyncTreeBuild, bForceTreeBuild);
		}
	}

	InstanceDataBuffers.Reset();
}

Steps to Reproduce
  1. Open attached repro project on 4.25 [Link Removed]
  2. Package project for Windows via File > Package project
  3. Launch the packaged game with -LLM commandline option
  4. Once the game launched, enter 'stat LLMFULL' in the console
  5. Enter 'stats.MaxPerGroup 100' to display more rows
  6. Pressing '1' key toggles the sublevel (loading the instantiated static mesh each time)
  7. Observe 'InstacedMesh' line in LLM stats (see attached screenshot)

Result:

InstancedMesh LLM counter keeps increasing.

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-109898 in the post.

0
Login to Vote

Fixed
Fix Commit15751139
Main Commit15751139
CreatedMar 3, 2021
ResolvedMar 19, 2021
UpdatedNov 30, 2022