When to call Addressables.Release

I have a question about when to release a UI prefab after loading it with Addressables.
Is it safe to call Addressables.Release immediately after instantiate the prefab loaded in Addressables?
Or shouldn’t I call Addressables.Release until I destroy the instantiated GameObject?
(This prefab explicitly contains only .prefab, but implicitly expects to contain .png, .mat, etc.)

The simple fact is that when you instantiate, there will be no reference to the data loaded in the addressables.
So, I think it’s okay to release it immediately. But is this not correct, or is it a case by case basis?

For safety reasons, of course, I think it’s better to do Addressables.Release after destroying the instantiated game object.

The sample code is shown below.

GameObject m_prefab;

// Start the UI
void startUI()
{
    StartCoroutine( loadPrefab() );
}

IEnumerator loadPrefab()
{
    var request = Addressables.LoadAssetAsync<GameObject>( "UI_prefab" );
    yield return request;

    var tmp = request.Result as GameObject;
    m_prefab = Instantiate(tmp) as GameObject;
    m_prefab.SetActive(true);

    // Are you sure you want to release it here?
    /*
    Addressables.Release( request );
    */
}

// End of UI
void endUI()
{
    GameObject.Destroy( m_prefab );
   
    // Or should I just Release it here?
    /*
    Addressables.Release( request );
    */
}

Use Addressables.InstantiateAsync instead of Addressables.LoadAssetAsync.
Release should be done during Destroy

Thanks, I just checked with EventViewer.
Unfortunately, when I use InstantiateAsync in the above case, the reference count does not decrease when
I call just GameObject.Destroy( m_prefab ) did not reduce the reference count.
Perhaps the reference count is not reduced until the “Scene” itself is destroyed.

So, I want to know about Addressables.LoadAssetAsync and Addressables.Release.
we will leave InstantiateAsync out of it this time.

I’ve been experimenting with ways to release the handle immediately.(i.e. immediately release after Instantiate)
Use ‘Asset Database seems’ to work fine.
However, when I used ‘Use Existing Build’, I had a lot of problems.

Here’s an example.

  • In the case of sprite, it will not be displayed at all.
  • In the case of prefab, even if you instantiate it, it often leads to problems such as missing under some conditions.
  • If it’s a byte file, it’s probably OK to release it immediately if you copy the bytes as new.

So basically, you should keep the handle until you are no longer using the addressable asset completely.
If I were to be greedy, I would have liked the behavior to be such that the above problem would be visible
even in ‘Use Asset Database’ mode.