Physics field clipmap buffer leaks when changing worlds

Hi,

When smoke testing our project, we ran into memory leak issues. Upon investigation, I discovered at least one of them can be attributed to the physics field clipmap buffer not being cleaned up properly.

From what I can tell, the buffer is created at the start of the level together with the physics field component. Then, it’s referenced by both the associated UAV and SRV resources. However, for some reason, the SRV resource ref counter increases once too many, preventing proper deletion. As I’m not too familiar with the rendering pipeline, I don’t really know exactly how this happens, but I did notice that `FRHIResource::GatherResourcesToDelete` fails to delete the SRV the first frame.

I’ve discovered it in our local version of the engine, but I managed to reproduce it in vanilla 5.7.4. The test project is attached.

Is this a known issue, and if so, is there a fix for this available?

For the time being I’m planning on disabling physics field components altogether with `r.PhysicsField.EnableField`. From what I can tell at first glance, there isn’t anything that is actively using the physics field in our project.

[Attachment Removed]

Steps to Reproduce

  1. Open a project (in -game mode)
  2. Log transient resources using `rhi.DumpResourceMemory -csv all transient=yes`
  3. Observe only one entry exists for `PhysicsField_ClipmapBuffer`.
  4. Open another level.
  5. Log transient resources again.
  6. Observe there are now two entries.
  7. Repeat until satisfied (or out of memory).
    [Attachment Removed]

I don’t see the attached project, so here it is

[Attachment Removed]

Hi,

I recently tracked this ~10 MB leak and I found the fix on //UE5/Main, CL 51168522 . In my test case, the physics field leak came from:

UWorld::FXSystem is a RAW pointer                        World.h:1857
    → the world's FFXSystemSet / FFXSystem /
      FNiagaraGpuComputeDispatch are NEVER DESTROYED       UE-315065
    → ~FNiagaraGpuComputeDispatch never runs,
      so AsyncGpuTraceHelper->Reset() never runs           NiagaraGpuComputeDispatch.cpp:252
    → FNiagaraAsyncGpuTraceProviderGsdf::m_ViewUniformBuffer
      keeps the dying world's LAST-FRAME view UB forever   NiagaraAsyncGpuTraceProviderGsdf.cpp:120
    → FRHIUniformBuffer::ResourceTable holds the clipmap SRV
    → SRV holds the FRHIBuffer, 10,485,760 B

Once I integrated CL 51168522, the leak was gone in my UE 5.7 test project. Can you integrate this CL and let me know if this works for you?

Regards,

Patrick

[Attachment Removed]