Search Unity

Bug Addressables Memory is not free

Discussion in 'Addressables' started by lleo52, Mar 17, 2023.

  1. lleo52

    lleo52

    Joined:
    Apr 8, 2013
    Posts:
    14
    Dear,

    I have used the Addressables.LoadSceneAsync() and Addressables.UnloadSceneAsync() now.

    First Memory Snapshot
    -> Scenario
    1) Load Scene Additive (Scene A)

    Second Memory Snapshot
    -> Scenario
    1) Load Scene Additive (Scene A)
    2) Unload Scene (Scene A)
    3) Load Scene Additive (Scene B)
    4) Unload Scene (Scene B)
    5) Load Scene Additive (Scene A)

    Ideally, both Snapshots should have the same memory.
    However, as shown in the attached picture, the combined mesh is accumulated every time it goes to another scene.

    unity version : 2021.3.16f1
    addressables version : 1.19.19

    upload_2023-3-17_18-5-42.png
     
    Last edited: Mar 17, 2023
  2. lleo52

    lleo52

    Joined:
    Apr 8, 2013
    Posts:
    14
    upload_2023-3-20_15-42-30.png

    I used two functions below and solved it.

    Resources.UnloadUnusedAssets();
    GC.Collect();

    Thanks
     
  3. andymilsom

    andymilsom

    Unity Technologies

    Joined:
    Mar 2, 2016
    Posts:
    294
    This looks like the they are embedded scene objects.
    When the scene loads, any embedded assets, like static batching, are a part of the scene.

    You would need to tell the scene unload options that you want to unload these embedded scene objects like so:
    Addressables.UnloadSceneAsync(m_SceneHandle, UnloadSceneOptions.UnloadAllEmbeddedSceneObjects);