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()

Scene Management

-

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

  1. 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.

Comments (2)

  1. 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();

  2. 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

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.