Figure: Diagnostic workflow: Persistent or temporary → Owner releases correctly → Memory after repeated use
Figure: Diagnostic workflow: Persistent or temporary → Owner releases correctly → Memory after repeated use

Cause and mechanism

A RenderTexture is a GPU image that receives camera output or other rendering. When creating these repeatedly, assign ownership and a clear end of use. Release frees the GPU allocation; Destroy destroys the Unity object and can also release its GPU resources. Check cleanup against how that particular texture was obtained.

Check and correct the setup

  1. Detach owned textures from camera/UI, release their backing storage, and destroy unneeded Unity objects.
    Release / Dispose
    Release / Dispose
  2. Return GetTemporary textures with ReleaseTemporary. Do not apply owned-object destruction to assets or borrowed textures.
    Release / Dispose
    Release / Dispose
  3. Match cleanup to the API: RTHandle.Release and buffer Dispose where appropriate. Clean up superseded size-dependent resources.
    Release / Dispose
    Release / Dispose

Limits and verification

Release leaves the RenderTexture object alive and its storage can be recreated. Remove users and verify memory stabilizes over repeated open/close cycles.

A focused diagnostic setup

As a diagnostic example, repeat opening/closing about ten times at fixed resolution. The count is a way to reveal growth, not a pass threshold.

Test in this order

  1. After warmup record texture counts, dimensions and references.
    Release / Dispose
    Release / Dispose
  2. Repeat measurements and distinguish owned objects from temporary pools and internal textures.
    Release / Dispose
    Release / Dispose
  3. Test resize, interrupted close and reopen against old references and cleanup.
    Release / Dispose
    Release / Dispose

Interpret the result

Process memory not dropping immediately does not prove a leak. Look for unneeded owned textures growing across cycles; pool retention is a separate case.

Related explanations

References