Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Resolved Atlas memory management

Discussion in 'Addressables' started by unity_CZ357CvJz8pzZA, Oct 19, 2021.

  1. unity_CZ357CvJz8pzZA

    unity_CZ357CvJz8pzZA

    Joined:
    Jun 28, 2019
    Posts:
    11
    Atlas is packed into bundle, it has no includeInBuild flag.
    What is the correct workflow of loading it into memory and unloading afterwards?
    This is simply managing assets on popup.
    What I tried:
    -loadAsync Atlas, and afterwards loadAsync Sprites out of it by [] address notation, assign them to images on popup.
    -release all these after popup close.
    By EventViewer everything is correct, both atlas and sprites getting a single reference, shown on screen, and after closing on release everything goes to 0 and so it should be unloaded from memory, right? but that is not the case... Memory profiler shows that the atlas texture is still in memory.
    Tried not to load directly atlas, but just reference sprites within it, still atlas texture is there...
    Tried to clear out referenced sprites from ui images before release(but that should not affect it as I understand), still same...
    I don't see any references to atlas, and before showing the popup - atlas texture is definitely not in the memory. but it just won't release afterwards...
    Why, what am I missing?
    initially was on 1.19.4 but upgraded now to 1.19.9 and nothing changed
     
  2. unity_CZ357CvJz8pzZA

    unity_CZ357CvJz8pzZA

    Joined:
    Jun 28, 2019
    Posts:
    11
    found the issue... it was exactly described at the When is memory cleared? section of Memory management
    manual. Problem was that I had a small item loaded from same bundle alongside the big atlas, and while unloading atlas, that small item was still there... preventing whole atlas texture from unload. But can't say why the manual call for Resources.UnloadUnusedAssets was not clearing it up as described. Anyway now I have to rethink how bundles are grouped otherwise I wouldn't be able to unload big atlases at all
     
  3. LilMako17

    LilMako17

    Joined:
    Apr 10, 2019
    Posts:
    43
    yea, for my project, I used the same code patterns as you, but I put all my sprite atlases in their own group and tagged it as "pack separately" so each atlas would have it's own bundle. That way you avoid the memory issue gotcha you described with having too many unrelated dependencies.