- Home /
Release an Addressable Asset issues
Hey folks,
I'm having a couple of issues with releasing Addressable assets. I've tried 2 approaches to perform the release operation: 1. call my AssetReference.Release() 2. call Addressables.Release() with the handle returned from Addressables.LoadAssetAsync<T>
Both methods do not seem to work as seen in the attachments.
I also tried to print the Addressables.GetDownloadSizeAsync(key).Result; and as seen in the 2nd attachment even after "releasing" the asset, the memory is still retained (size 0 means the asset is cached).
Here is the full code:
 public class AddressablesAssetService : IAssetService
     {
         private readonly Dictionary<IRetainAssetKey, AsyncOperationHandle> _retainedAssets;
 
         public AddressablesAssetService()
         {
             _retainedAssets = new Dictionary<IRetainAssetKey, AsyncOperationHandle>();
         }
 
         public IRetainAssetKey GetAssetKeyByPath(string path)
         {
             var fullPath = $"Assets/Resources_moved/{path}.prefab";
             var referenceId = AssetDatabase.AssetPathToGUID(fullPath);
             var reference = new AssetReference(referenceId);
             return new AddressableAssetKey(reference);
         }
 
         public UniTask<T> Retain<T>(IRetainAssetKey retainedAssetKey)
         {
             var addressableReference = (AssetReference)retainedAssetKey.Reference;
             var retainedAssetHandle = addressableReference.LoadAssetAsync<T>();
             _retainedAssets[retainedAssetKey] = retainedAssetHandle;
             return retainedAssetHandle.ToUniTask();
         }
 
         public void Release(IRetainAssetKey releasedAssetKey)
         {
             if (!_retainedAssets.TryGetValue(releasedAssetKey, out var handle))
                 return;
 
             var addressableReference = (AssetReference)releasedAssetKey.Reference;
             var guidToAssetPath = AssetDatabase.GUIDToAssetPath(addressableReference.AssetGUID);
             var key = guidToAssetPath.Replace(@"Assets/Resources_moved/", "").Replace(".prefab", "");
 
             Addressables.GetDownloadSizeAsync(key).Completed += (r) =>
             {
                 Debug.LogError("before " + key + " " + r.Result + " " + r.IsDone);
             };
 
 // remove from manager
             _retainedAssets.Remove(releasedAssetKey);
 
 
 // method 1
             //addressableReference.ReleaseAsset();
 // method 2
             Addressables.Release(handle);
 
             Debug.LogError($"Releasted {key}");
             Addressables.GetDownloadSizeAsync(key).Completed += (r) =>
             {
                 Debug.LogError("after " + key + " " + r.Result + " " + r.IsDone);
             };
         }
     }

Any help would be appreciated!
Thanks
An update about new findings: 1. AssetDatabase is part of UnityEngine.Editor, a mistake on my part which I missed (using Resharper for imports) 2. Found the guide below (link at the bottom), which lead me to find that my groups were indeed packed together - thus possibly not being released
Will update once I resolve the 1st points
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                