Addressables 1.19 Asynchronous Reference Counting Changes Impact Rapid Scene Transitions
0 reputation · 17 Apr 2020, 10:26 UTC
0 reputation · 17 Apr 2020, 10:26 UTC
Goal: Determine if the asynchronous reference counting in Addressables 1.19 requires an explicit wait before releasing handles during rapid scene transitions to avoid memory retention.
The documentation still recommends the synchronous ReleaseInstance pattern, yet the internal reference count is now decremented asynchronously. When InstantiateAsync and ReleaseInstance are called in quick succession—such as during frequent scene loads—the handle may report a non‑zero count, leaving the instantiated GameObject in memory. This mismatch creates uncertainty about the safe timing for cleanup without introducing frame‑delay overhead.
Questions:
31775 reputation · 17 Apr 2020, 11:35 UTC
In Addressables 1.19, you do not need to manually wait for AsyncOperationHandle.IsDone or yield a frame before calling ReleaseInstance. The system is designed to queue the decrement of the reference count; however, the actual unloading of the asset from memory is not instantaneous and depends on the underlying Unity resource management cycle.
The perceived "memory retention" during rapid scene transitions is typically not a failure of the reference count to reach zero, but rather a timing gap between the logical release (decrementing the counter) and the physical unload (garbage collection and resource purging). Because the internal counting is asynchronous, a rapid loop of InstantiateAsync followed by ReleaseInstance can cause the reference count to fluctuate faster than the system can purge the assets, leading to temporary memory peaks.
To balance immediate cleanup with asynchronous behavior, avoid tight loops of instantiation and release. Instead, use a managed lifecycle approach:
yield return null specifically to "wait" for the counter; this often introduces stutter without guaranteeing the asset is purged from RAM.ReleaseInstance calls during the scene teardown phase.Resources.UnloadUnusedAssets() after the Addressables release calls have been issued. This forces Unity to collect the assets that Addressables has logically marked for release.To determine if you have a genuine leak or simply a delayed unload, use these tools:
Diagnostic Detail Needed: Are you utilizing Addressables.LoadAssetAsync to get a reference that is then passed to Instantiate, or are you using Addressables.InstantiateAsync directly? The handling of the underlying asset handle differs between these two patterns.
Use comments to ask for clarification. Post a solution as an answer.
31,775 reputation · 17 Apr 2020, 13:21 UTC
In Addressables 1.19 the internal reference count is updated on a background worker only after the AsyncOperationHandle reports completion. If you call ReleaseInstance immediately after InstantiateAsync without waiting for IsDone, the handle may still show a non‑zero count, keeping the GameObject in memory until the asynchronous decrement finishes—typically within the next frame. Therefore, to guarantee the count reaches zero before you release, yield one frame (or await the handle) before calling ReleaseInstance. This prevents temporary memory spikes during rapid scene transitions without adding noticeable overhead.