0

I've written myself a helper class to handle the loading and unloading of addressables, but I can't determine if it is working correctly as I don't see the results I'm expecting (f.e. memory is not the same before loading when unloading, though it does go down).

I profiled with the Memory Profiler and got the following results.

enter image description here

The Event Viewer releases the resources correctly (there's only the InitializationObjectsOperation where I don't know what it is and how to get rid of it, I'm not using InstantiateAsync).

The class has the following methods for loading and unloading (coupled with an object pool that instantiates a pool whenever a game object addressable is loaded by using the result of the handle, and destroy the game objects and the pool when unloading is required).

        private IEnumerator LoadObjects<TObject>(IList<object> keys, Addressables.MergeMode mergeMode = Addressables.MergeMode.Union)
    {
            var locations = Addressables.LoadResourceLocationsAsync(keys, mergeMode, typeof(TObject));

            yield return locations;
            
            foreach (var location in locations.Result)
            {
                    if (_allObjectAsyncOperationHandlesByLocationKey.ContainsKey(location.PrimaryKey))
                    {
                            continue;
                    }
                    
                    var asyncOperationHandle = Addressables.LoadAssetAsync<TObject>(location);

                    asyncOperationHandle.Completed += obj =>
                    {
                            if (obj.Status == AsyncOperationStatus.Succeeded)
                            {
                                    _allObjectAsyncOperationHandlesByLocationKey.Add(location.PrimaryKey, obj);
                                    _allAddressableLocationKeysByObject.Add(obj.Result, location.PrimaryKey);

                                    if (obj.Result is GameObject gameObj) OnGameObjectLoaded?.Invoke(gameObj);
                            }
                            else
                            {
                                    // TODO: 
                            }
                    };
            }
            
            Addressables.Release(locations);
    }
Charles Nough
  • 353
  • 1
  • 3
  • 15

1 Answers1

0

when you initialize Addressable it may use extra memory, try running your tests after initialization.