About when and how to release assets when using addressable asset?

Hi, I am new for addressable ,for me I am confusing about when and how to release loaded asset .For instance

        handle = Addressables.LoadAssetAsync<GameObject>("Cube");
        handle.Completed += (handle) =>
        {
            if (handle.Status == AsyncOperationStatus.Succeeded)
                Instantiate(handle.Result);

            Addressables.Release(handle);
        };

I got a address asset called “Cube”,which was a prefab, should I release the loaded asset just like above?

Anyway ,sometimes I need to Instantiate the “cube” serveral times.And should I use the same function for instantiating? Or it would be more rational using “cache” to keep the “handle.Result”?

It’s depend, Unity’s document recommending that you should use Addressables.InstantiateAsync(key) and Addressables.ReleaseInstance(key) for prefab workflow so that Unity can track the creation and deletion of object for you.

With your code, you’re instantiating object from addressable and release it right away, because of this all assets, materials, … of that object will be unload from memory and will lead to some error with the instantiated object.

1 Like