Addressables assets not unloading

In my case addressable assets did not unload in runtime and in the editor. I using AssetReferences for loading new levels, but when I was unloading previous data, they were not unloaded. For unloading I use this code:

sublevelsReferences[i].ReleaseInstance(instances[i]);
               
sublevelsReferences[i].ReleaseAsset();

For debugging my problem I used an Addressable Profiler and I see that Mono Heap will increase from loading to loading, but not decrease for unloading assets. But references in Addressable Profiler was deleted.

The same thing I tried to compress and create bundles of assets separately, but this did not help.

What I did wrong?

I’ll kick this to the team for some guidance. Which version of Addressables are you using?

I have a similar problem here using Addressables.LoadAsset(path) where TestSO is a ScriptableObject containing one sprite named “icon”, for the moment.

NB : I have both the SO and the sprite marked as “Addressable”.

using System.Collections;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.UI;

public class TestLoader : MonoBehaviour
{
    public Image image;
    public string path;
    public float delay;

    private bool isAssetRequested = false;
    private bool canLoadAssets = false;

    private void Awake()
    {
        Addressables.InitializeAsync().Completed += (op) => canLoadAssets = true;
    }

    private void Update()
    {
        if (!canLoadAssets)
            return;

        if (Input.GetKeyDown(KeyCode.P) && !isAssetRequested)
        {
            isAssetRequested = true;
            Addressables.LoadAssetAsync<TestSO>(path).Completed += OnLoaded;
        }
    }

    private void OnLoaded(AsyncOperationHandle<TestSO> _Handle)
    {
        if (_Handle.Status == AsyncOperationStatus.Failed)
        {
            isAssetRequested = false;
            return;
        }
        else
        {
            Debug.Log("SO Loaded");
            image.sprite = _Handle.Result.icon;

            StartCoroutine(ReleaseDelay(_Handle));
        }
    }

    private IEnumerator ReleaseDelay(AsyncOperationHandle<TestSO> _Handle)
    {
        yield return new WaitForSeconds(delay);

        image.sprite = null;

        Addressables.Release(_Handle);
        //Resources.UnloadUnusedAssets();

        Debug.Log("SO Unloaded");

        isAssetRequested = false;
    }
}

Here I simply load a ScriptableObject (TestSO) containing one sprite and affect this sprite to a UI Image in my scene. Then, after a delay, I set the Image’s sprite to null and unload the asset.

The addressable profiler seems to behave normally but the basic profiler of unity does not show any memory freed after unloading the SO (using the “Simulate Groups PlayMode Script”).

Uncommenting the “//Resources.UnloadUnusedAssets();” seems to work and free the memory but I read on the documentation that this operation is very slow and so it wouldn’t fit for my need to free my loaded asset during gameplay.

If anyone has insights about this, I would love to hear it too.

Edit : Using Addressables v1.8.4

Hi again,

I just tested profiling a build and everything worked fine, seems like its an editor bug (or just a desired behaviour to cache references in the editor). Anyway by reading your issue again I think it might not be the exact same problem. As the documentation says about Addressables, always check twice by connecting a profiler to a build.

Hey @OnionFan
Make sure you call Resources.UnloadUnusedAssets if you haven’t already. Check the guide here for more:
https://docs.unity3d.com/Packages/com.unity.addressables@1.13/manual/MemoryManagement.html

Hello. I have one problem for it. Can I use both local addressables and remote addressables at the same time?

if you release some instance from bundle then it will not be released while bundle itself is needed. Your instance will be released after the bundle will be unloaded