cesium-unity icon indicating copy to clipboard operation
cesium-unity copied to clipboard

Dispose UnityWebRequest when we're done with it

Open kring opened this issue 1 year ago • 0 comments

Mentioned on the forum here: https://community.cesium.com/t/potential-memory-leak-due-to-unsafe-use-of-unitywebrequest/38030

UnityWebRequest has a Dispose method, which we should call when the request completes (or fails). We're currently explicitly disposing the "download handler" but not the request itself. This could lead to memory growth if the garbage collector doesn't clean these up right away. And it also creates unnecessary work for the finalizer, which has performance implications.

UnityWebRequest also has disposeDownloadHandlerOnDispose and disposeUploadHandlerOnDispose properties, and they're set to true by default, so we can probably switch to disposing the request instead of the handler.

kring avatar Jan 28 '25 23:01 kring