Search Unity

Issue with partially unload an asset.

Discussion in 'Addressables' started by Lukas-Labaj, Sep 24, 2019.

  1. Lukas-Labaj

    Lukas-Labaj

    Joined:
    Nov 22, 2012
    Posts:
    36
    Hi @unity_bill

    In docs for memory management there is one section about unloading partially unload asset:
    https://docs.unity3d.com/Packages/com.unity.addressables@1.2/manual/MemoryManagement.html

    This case doesnt work for me. I cant unload only just one asset from memory. Even, Im making mirroring load-unload operation there is still reference to asset (in my case im trying load/unload Sprite). In detailed memory profile i got this ref (see screenshot).

    Am I doing something wrong?

    Loading two different sprites from same bundle:
    Code (CSharp):
    1.  
    2. Addressables.LoadAssetAsync<Sprite>("Assets/Sprites/A/element_fire.png").Completed += handle =>
    3. {
    4.       _opCache.Add(handle);
    5.       image.sprite = handle.Result;
    6. };
    7.  
    8. Addressables.LoadAssetAsync<Sprite>("Assets/Sprites/B/element_fire_1.png").Completed += handle =>
    9. {
    10.     image2.sprite = handle.Result;
    11. };
    12.  
    Trying unload only one sprite:
    Code (CSharp):
    1.  
    2.            foreach (var sprite in _opCache)
    3.            {
    4.                 Addressables.Release(sprite);  
    5.             }
    6.          
    7.             _opCache.Clear();
    8.                          
    9.             image.sprite = null;
    10.  
    11.             Resources.UnloadUnusedAssets();
    12.  

    I found that reference staying inside of LRUCacheAllocationStrategy, as released operation with referenece to asset (m_Result). When I cleared result to null in ProviderOperation.Destroy() everythings works now. Can you please check/confirm this issue and suggest fix for that?
     

    Attached Files:

    Last edited: Sep 27, 2019
  2. PaulBurslem

    PaulBurslem

    Unity Technologies

    Joined:
    Oct 7, 2016
    Posts:
    79
    That definitely sounds like a bug. We will take a look at your suggested solution and make sure the references get cleared in the Destroy in all cases (there may be more than just the ProviderOperation that have this issue)
     
  3. Lukas-Labaj

    Lukas-Labaj

    Joined:
    Nov 22, 2012
    Posts:
    36
    Hi, is there any progress on that please?