UMaterialParameterCollectionInstance objects leaking when streaming levels

Hi,

I noticed that UMaterialParameterCollectionInstance objects created for use in some streamed levels are not destroyed even after the streamed level is unloaded. The specific sequence is:

  • Gameplay starts with Level 1
  • Level 2 is loaded through streaming
  • Level 2 requires a specific MaterialParameterCollection, e.g. MPC_X, for use from one of its materials.
  • While loading MPC_X, it registers corresponding UMaterialParameterCollectionInstance objects with both Level 1 and Level 2 (see code in UMaterialParameterCollection::PostLoad).
  • After some gameplay Level 2 is unloaded but Level 1 remains loaded. However, the UMaterialParameterCollectionInstance corresponding to MPC_X remains registered with Level 1, thereby leaking both the collection instance and MPC_X.

To fix this, I was thinking of making the following changes:

  • Change the Collection member of UMaterialParameterCollectionInstance to be a weak pointer.
  • Override BeginDestroy in UMaterialParameterCollection and remove corresponding collection instances from all worlds.

Would that be the best way to fix this issue? Or is there another way?

(The leak by itself isn’t critical as the objects don’t take up too much memory, but the objects are spamming a “leak report” I’m working on, so it would be nice to clean those up properly)

Thanks,

Manu.