Memory Leak in TextureVideoSource.Update()
Summary
TextureVideoSource.Update() does not get cleaned up properly by TextureVideoSource.Stop() and TextureVideoSource.Dispose() are called from Unity's OnApplicationQuit(). Basically, if video is still being streamed when you stop the app (from in the Unity editor), it causes a memory leak. This does not happen if I stop streaming or leave the room before ending the app.
Environment
LiveKit Unity SDK Version: 1.2.5 Unity Version: 6000.1.5f1 Platform: MacOS LiveKit Server Version: 1.9.0
Analysis
The memory leak appears to be in the internal ReadBuffer() method called by source.Update(). The leak cannot be mitigated by:
Proper disposal patterns Garbage collection calls Setting cleanup flags Different RenderTexture formats
Workarounds Attempted
Controlled cleanup timing - Still leaks memory Reduced update frequency - Reduces leak rate but doesn't eliminate it Early termination of Update() calls - Breaks video streaming functionality Alternative RenderTexture formats - No improvement
TLDR
When the app is stopped in the Unity editor with video actively streaming, the TextureVideoSource.Update coroutine does not get cleaned up in time and results in a memory leak. If this is a known issue, or if there's known workaround, please get back to me.
Hi @rubyknickerbocker, thank you for the detailed report—we will investigate the issue.
ive also had a similar problem and there are other issues similar to this in unity. from what ive seen it seems to be happening somewhere in the native array relating to using gpu callbacks. the posts related to this are:
https://discussions.unity.com/t/asyncgpureadback-requestintonativearray-causes-invalidoperationexception-on-nativearray/818225/79
https://discussions.unity.com/t/asyncgpureadback-requestintonativearray-what-am-i-doing-wrong/812861
this seems to be a known issue on unity side... so i'm not sure how to go about it. it seems to be more a warning sort of issue rather than serious memory leak as far as i can tell but im quite new to this so i'm not sure.