Skip to content

Fix leaked textures on resolution change and quit#277

Open
MaxHeimbrock wants to merge 1 commit intomainfrom
max/fix-leaked-textures
Open

Fix leaked textures on resolution change and quit#277
MaxHeimbrock wants to merge 1 commit intomainfrom
max/fix-leaked-textures

Conversation

@MaxHeimbrock
Copy link
Copy Markdown
Contributor

Summary

Fixes texture/buffer leaks in the video source paths and on Meet sample shutdown.

  • WebCameraSource, CameraVideoSource, ScreenVideoSource: each one reallocated RenderTexture / Texture2D / NativeArray<byte> when the source resolution changed, but did not release/destroy/dispose the previous instances first. The old GPU and native allocations leaked on every resize.
  • WebCameraSource.Dispose: previously did not release _tempTexture (the parent RtcVideoSource.Dispose only frees _previewTexture and _captureBuffer). Added an override.
  • CameraVideoSource.Dispose / ScreenVideoSource.Dispose: previously had a ClearRenderTexture() that only called Release() (no Object.Destroy), and was not invoked from Dispose. Added overrides that fully release + destroy the _renderTexture when called from user code.
  • MeetManager.OnDestroy: only stopped the WebCamTexture. If the scene was destroyed (or app quit) while still in a call, every track, stream, and tile remained allocated. Now disconnects the room and runs CleanUpAllTracks().

These bugs primarily compound on resolution changes (camera flips, screen resizes, orientation changes) and on app/scene shutdown — they don't fully explain steady-state per-frame growth, but they do contribute to long-running session bloat.

Test plan

  • Manual: open Meet sample, start a call, toggle camera on/off several times, check Memory Profiler — RT/Tex2D count should stay flat across resolution changes
  • Manual: open Meet sample, start a call, close the scene/quit — confirm Unity does not log "leaked Object" warnings for textures or video sources
  • Existing EditMode/PlayMode tests still pass

🤖 Generated with Claude Code

Video sources (WebCameraSource, CameraVideoSource, ScreenVideoSource) reallocated
their RenderTexture/Texture2D/NativeArray on resize without releasing the previous
instances, leaving the old GPU and native allocations to leak. Dispose() also did
not free the RenderTexture/_tempTexture in the camera source paths.

Meet sample's MeetManager.OnDestroy did not clean up tracks and streams when the
scene is destroyed while still connected, leaking everything CleanUpAllTracks
would have released.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant