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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Addressables.LoadAssets memory leak

Discussion in 'Addressables' started by Alexaroth, Mar 30, 2019.

  1. Alexaroth

    Alexaroth

    Joined:
    Feb 4, 2019
    Posts:
    29
    So I'm doing this, with the following assumptions:


    Addressables.LoadAssets<GameObject>("Level1Map", op =>
    {
    Debug.Log("LOADED MAP ASSET");
    });


    I assume this loads the asset in memory, ref counter goes to 1

    Then I do:


    Addressables.Instantiate("Level1Map", new Vector3(0, 0, 0), Quaternion.identity).Completed += (op) =>
    {
    CurrentLevelPrefab = op.Result;
    Debug.Log("Level Loaded!");
    };


    I assume this instantiates and stores the gameObject, ref counter goes up to 2.


    When i wanna switch map, I do:


    Addressables.ReleaseInstance(CurrentLevelPrefab);


    Ref counter goes down to 1. I then do:


    Addressables.ReleaseAsset("Level1Map");


    Ref count goes down to 0, asset gets unloaded.

    however the ref count is 1 in the profiler, even after I switch the scene. What is wrong with my code/assumptions?

    Any help would be appreciated!
     
    MNNoxMortem likes this.
  2. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    @Alexaroth I recommend to create a new project and if you can recreate it there create a bug report. This is usually the only way to actually get things like these, if they are indeed bugs, to be fixed by unity.
     
  3. Alexaroth

    Alexaroth

    Joined:
    Feb 4, 2019
    Posts:
    29
    I can do that sure but I want to also know if my assumptions are correct or not. There is barely any documentation out there, I have to look up threads in this forum and search for Unity dev replies to actually get a picture of how this system works
     
    MNNoxMortem likes this.
  4. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    @Alexaroth I'd say your ref-count example looks pretty straightforward and it might be a bug. Better have a dev actually look at it.
     
  5. Alexaroth

    Alexaroth

    Joined:
    Feb 4, 2019
    Posts:
    29
  6. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    @Alexaroth have you used the Unity Bug Reporter to report that project? Help > Report a Bug?
     
  7. Alexaroth

    Alexaroth

    Joined:
    Feb 4, 2019
    Posts:
    29
    yeap
     
    MNNoxMortem likes this.
  8. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Thanks for filing an actual bug. That is a huge help to us.

    Of note though, the issue is that you cannot release by address. Your code of `Addressables.ReleaseAsset("Level1Map");` will not work. In the upcoming release, we are improving the logging to let you know when Release is called on something we don't recognize. Though thinking about it more, I think that log could probably be more explicit still. I'll think on it.

    Either way, you need something more like:

    Code (CSharp):
    1. Addressables.LoadAsset<GameObject>("level1").Completed += e =>
    2.         {
    3.             m_asset = e.Result;
    4.             Debug.Log("LOAD ASSET TEST");
    5.         };
    6.  
    7.  
    8. //and later
    9.  
    10. Addressables.ReleaseAsset(m_asset);
    11.  
     
  9. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Upon thinking about this a little more, we are going to explore making Release("address") work. We can't for instances, but for a loaded asset, it is most likely possible. Just fyi.
     
    Alexaroth and MNNoxMortem like this.
  10. lifetree

    lifetree

    Joined:
    Mar 28, 2014
    Posts:
    49
    We are having an addressable memory leak bug and wondering if this ever got "fixed"?
     
  11. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,796