Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Addressables Possible Memory Leak Loading Scenes

Discussion in 'Addressables' started by VoodooDetective, Jan 29, 2022.

  1. VoodooDetective

    VoodooDetective

    Joined:
    Oct 11, 2019
    Posts:
    239
    I'm using addressables to load scenes for our game. In those scenes we have 2D sprite animations. Those sprite animations use sprite atlases to hold the sprites.

    When I unload the current scene and move on to the next, sometimes those sprite atlases and animations stick around in memory. I've used the memory profiler and as far as I can tell, the only thing referencing the sprite atlas is the sprites and the only thing referencing the sprites is the animations and the only thing referencing the animation clips are... the animation clips and the sprites. And it's completely random which clips will stick around in memory referencing themselves.


    I'm using Resources.UnloadUnusedAssets after loading the new scene. It seems like non-deterministically, the memory isn't being freed.
     
    Last edited: Jan 29, 2022
  2. VoodooDetective

    VoodooDetective

    Joined:
    Oct 11, 2019
    Posts:
    239
  3. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,475
    There is that bug but if also double check that the same behavior happens in a build. The bug is about a Texture2D, not a sprite and sprites and atlases can operate a bit differently in the editor.
     
  4. VoodooDetective

    VoodooDetective

    Joined:
    Oct 11, 2019
    Posts:
    239
    Thanks very much for your reply! So this bug is happening in our build. I don't know about the editor, it's too difficult to profile accurately.

    I also just noticed that bug is 6+ months old which is very troubling. The way our game is organized, ALL addressables are in one big group. Between levels, we call Resources.UnloadUnusedAssets to get rid of stuff.

    I noticed that Unity non-deterministically will leave assets in memory even after that call. Sometimes the call cleans everything up, sometimes it doesn't. And like I said, when I dig in in the memory profiler, I see things referencing themselves at the deepest level. Perhaps it's the same bug? It's actually a huge problem for us because our animations are very big and this bug is causing our game to get killed by the operating system on iPhones.

    I'm contemplating breaking up the big default group into a bunch of sub-groups, but that's a tremendous amount of work and I doubt it'll end up being as simple/efficient as the current method. Except the current method doesn't work because of the memory leak.
     
  5. andymilsom

    andymilsom

    Unity Technologies

    Joined:
    Mar 2, 2016
    Posts:
    294
    This bug was fixed in 1.18.14. And appears to have slipped the net from the issue tracker being stuck at "In review" and should be listed as "Fixed in 1.18.14".
    That bug was on the Addressables side, where we missed a callback holding onto loaded Assets.

    We currently do not know of any existing bugs where we keep and references to loaded Assets once they have all been Released within the Addressables API.

    If you are still seeing something like this, where you are expecting no references to an Object and it is not unloading. Then a bug report will be the best route. This could be either Addressables holding it when it shouldn't or possibly internal at the engine level.

    It is also good to note that this should only be profiled in a build (Can use Use Existing Build in Editor from Addressables). The Editor can hold onto Assets loaded through the Editor AssetDatabase for its purpose and could be working as intended.
     
    VoodooDetective and MartinTilo like this.