Addressables-Sample icon indicating copy to clipboard operation
Addressables-Sample copied to clipboard

Not all references are being released

Open wormszer opened this issue 5 years ago • 1 comments

https://github.com/Unity-Technologies/Addressables-Sample/blob/05119a010bcf01f3d75a9fd03f1e0dd3ad5de874/Basic/ComponentReference/Assets/Scripts/ComponentReference.cs#L31

AsyncOperationHandle<TComponent> GameObjectReady(AsyncOperationHandle<GameObject> arg)
{
        var comp = arg.Result.GetComponent<TComponent>();
        return Addressables.ResourceManager.CreateCompletedOperation<TComponent>(comp, string.Empty);
}

Using the AssetReferenceComponent i see some references to things i have released still sticking around. Adding this extra release here seems to allow things to load and the other references i was seeing are going away now.

AsyncOperationHandle<TComponent> GameObjectReady(AsyncOperationHandle<GameObject> arg)
    {
        var comp = arg.Result.GetComponent<TComponent>();
        Addressables.Release(arg);
        return Addressables.ResourceManager.CreateCompletedOperation<TComponent>(comp, string.Empty);
    }

Is this a correct fix?

wormszer avatar Feb 22 '20 03:02 wormszer

Hi @wormszer thanks for reporting this issue! There is a custom Release function that's been implemented (ComponentReference.ReleaseInstance). You can use ReleaseInstance to correctly release all the resources.

    var handle = ColorShifterReference.InstantiateAsync();
    handle.Completed += InstantiateDone;
    handle.WaitForCompletion();
    ColorShifterReference.ReleaseInstance(handle);

Also for future bugs, I would recommend submitting a bug through the regular submission process https://unity3d.com/unity/qa/bug-reporting. This way issues like these can be more easily flagged in our system.

kirstenpilla avatar Jan 14 '22 19:01 kirstenpilla