Search Issue Tracker
By Design
Votes
2
Found in
2017.4.0f1
2017.4.14f1
2018.3.0a1
2019.1.0a1
2019.2.0a1
Issue ID
1117838
Regression
No
Memory leak after using SceneManager.UnloadSceneAsync()
How to reproduce:
1. Open attached project "StreamingSceneDemo"
2. Enter Play Mode, click "StartUnload" in Game View and wait 4 seconds until other scene is unloaded
3. Open Profiler, select Memory, select Detailed from dropdown menu and click "Take Sample Editor"
4. In shown table below expand Scene Memory/Mesh and Scene Memory/Material
Expected result: No unreferenced memory calls are shown
Actual result: Combined Mesh (root: scene) and material memory leaks are shown
Reproduced with: 2017.4.18f1, 2018.3.3f1, 2019.1.0a14, 2019.2.0a1
-
flapierrelds
Jan 27, 2022 21:11
I misread the bug description. I'm looking at a leak with Addressables and though this bug was for this version of the unload async. For anyone seeing this, you should call something like this to release everything using the Addressables:
yield return Addressables.UnloadSceneAsync(handle);
yield return Resources.UnloadUnusedAssets(); -
flapierrelds
Jan 27, 2022 21:01
Hello,
Addressables.UnloadSceneAsync(...) does not take the UnloadSceneOptions.UnloadAllEmbeddedSceneObjects parameter. Did you mean that we should call SceneManager.UnloadSceneAsync(...) with this option and then call Addressables.Release() on the handle?
Something like:
yield return SceneManager.UnloadSceneAsync(handle.Result.Scene, UnloadSceneOptions.UnloadAllEmbeddedSceneObjects);
Addressables.Release(handle);
Thanks
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Articulation Body with 'Revolute' Joint Type has erratic behavior when Upper Limit is set to above 360
- WebGL Player fails to render Scene when Terrain with Detail Mesh is added and WebGPU Graphics API is used
- Inconsistent errors are logged when different types are passed into the Query "Q<>" method in UIToolkit and the ancestor VisualElement is null
- Crash on GetMaterialPropertyByIndex when opening a specific Scene
- Discrepancies in the styling are present when using a TSS file instead of a USS file in custom EditorWindow
Resolution Note:
UnloadSceneAsync() will only unload GameObjects not assets, by design.
This is because some assets in the scene could be referenced by objects in other scenes.
To unload _everything_ referenced by this scene UnloadSceneAsync() should be called with the option UnloadSceneOptions.UnloadAllEmbeddedSceneObjects.
Unused assets (those assets not referenced by any scene) can be unloaded by using Resouces.UnloadUnusedAssets(), though this should be used sparingly as it can be slow.