Addressables.LoadAssets memory leak

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!

1 Like

@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.

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

1 Like

@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.

Okay, done: https://drive.google.com/open?id=1SQKlQT5MLG7e_PO3SC9nCFP-z35AOcYu

Repro steps: Created empty project, imported addressable, created one prefab, addressed it, built addressable, then ran the code logic I described above

@Alexaroth have you used the Unity Bug Reporter to report that project? Help > Report a Bug?

yeap

1 Like

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:

Addressables.LoadAsset<GameObject>("level1").Completed += e =>
        {
            m_asset = e.Result;
            Debug.Log("LOAD ASSET TEST");
        };


//and later

Addressables.ReleaseAsset(m_asset);

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.

2 Likes

We are having an addressable memory leak bug and wondering if this ever got “fixed”?

If you havne’t, @lifetree , could you file a bug report for us?