Search Unity

troubleshooting memory leak

Discussion in 'Asset Bundles' started by jchowdown-asla, Jun 12, 2021.

  1. jchowdown-asla

    jchowdown-asla

    Joined:
    May 10, 2017
    Posts:
    22
    Hi, I want to understand how memory allocation for assets works so I created a simple test project:

    1. create asset bundle containing a single prefab that references a 10mb sprite asset
    2. run game and do the following
      1. load asset bundle
      2. load prefab
      3. instantiate prefab instance
      4. destroy instance
      5. call Unload(false) on original loaded assetbundle
    I see a new texture instance created when #2 is done but I don't see that texture instance being freed after #5 finishes. Why not? If the engine is keeping the texture in memory as an optimization, is there a way to tell it to free it up right away?

    I see that bundle.Unload(true) might do what I need but why do I have to, since there are no more references to it in the game? Also, bundle.Unload(true) will unload the whole bundle, which might contain other prefabs which I might need.
     
unityunity