Search Unity

Question Unloading scene asset bundle doesn't seem to have an effect

Discussion in 'Asset Bundles' started by AmitChBB, Feb 23, 2022.

  1. AmitChBB

    AmitChBB

    Joined:
    Feb 16, 2021
    Posts:
    37
    Hi there :)

    I seem to have a bug where unloading a scene asset bundle doesn't seem to have the expected effect on memory.

    I am moving from scene A, loaded from asset bundle A, to scene B, loaded from asset bundle B. They are both about 18.8MB in size as a compressed asset bundle.
    In my logic, about a second after moving to scene B, I unload the scene A asset bundle with
    unloadAllLoadedObjects
    set to
    true
    .

    However, when using the profiler, I see that while the function is called, and it has some effect (textures, audioclips, etc are decreased by a few MBs), the memory of the game does not drop significantly (I expected it to be at least the compressed size + uncompressed size of loaded assets).

    During the scene transition, I can see that the memory significantly increases (about 400MBs) and then drops back to normal. This makes sense because a new scene is loaded and the old one is discarded.

    Am I missing something? Was I supposed to see a memory drop at all, or does the scene transition take care of it already? Please advise!
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,461
    Because assets for both scenes needed to be in memory for the second of overlap, the native buffers that hold them needed to be expanded to make room for those. Those buffers rarely reset their size afterwards but they should then contain "Unused but Reserved" space that is ready for new needs for memory, e.g. the next scene load.
    In case you're not yet using the Memory Profiler package for analyzing this, you may want to give that a try.