Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by xCeas · May 08, 2021 at 05:47 PM · unity 5assetdatabase

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);
             };
         }
     }

alt text

Any help would be appreciated!

Thanks

memory-aloc.png (22.9 kB)
assets-download-size-before-after.png (42.0 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image xCeas · May 09, 2021 at 05:59 PM 0
Share

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

https://www.gamasutra.com/blogs/RubenTorresBonet/20200317/359697/When_is_Unity_REALLY_unloading_your_assets_from_memory.php

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

208 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity Git - Ignore Library 2 Answers

Unity 5.3.3f1: How to set an object as AssetBundle by script? 0 Answers

How fast save assets ( AssetDatabase.CreateAsset) 0 Answers

Unable to load asset at path with unity tutorial code 1 Answer

Get the number of false bools in GameObject[] (array) 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges