Search Unity

Texture and meshes still in memory even after release.

Discussion in 'Addressables' started by murat303, Aug 10, 2019.

  1. murat303

    murat303

    Joined:
    May 22, 2014
    Posts:
    38
    Hi, I'm Instantiate prefab with addressable than i'm destroying object and release the AssetReference.
    But when i check the profiller textures and meshes (in prefab) are still there and consuming memory. My code is below, what could cause this? Is there a mistake in the code?

    I'm using Unity 2019.2.0f1 and Addressable 1.1.7

    Code (CSharp):
    1. public AssetReference adress;
    2. GameObject refObject;
    3.  
    4. void OnEnable()
    5. {
    6.     adress.InstantiateAsync(transform.GetChild(0)).Completed += Completed;
    7. }
    8.  
    9. void Completed(UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle<GameObject> obj)
    10. {
    11.     refObject = obj.Result;
    12. }
    13.  
    14. void OnDisable()
    15. {
    16.     if (refObject != null)
    17.     {
    18.         adress.ReleaseAsset();
    19.         Addressables.ReleaseInstance(refObject);
    20.     }
    21. }
     
  2. murat303

    murat303

    Joined:
    May 22, 2014
    Posts:
    38
    Also
    1) i'm using Vacuum Shaders - Curved World, my project works smoothly on ios but everything looks pink in android. (Only in Editor, no problem with the android device) I rebuild player content and fixed duplicated bundle dependencies in analyze section. I'm using Packed Play Mode in Play Mode Script.

    2) Some prefabs give this error;
    Exception encountered in operation Resource<GameObject>(Accident2.prefab): Unknown error in AsyncOperation
    UnityEngine.AsyncOperation:InvokeCompletionEvent()


    Exception encountered in operation Instance<InstanceProvider>(Resource<GameObject>(Accident2.prefab): Dependency operation failed with System.Exception: Unknown error in AsyncOperation.
    UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:<.ctor>b__26_0(AsyncOperationHandle)
    DelegateList`1:Invoke(AsyncOperationHandle) (at Library/PackageCache/com.unity.addressables@1.1.7/Runtime/ResourceManager/Util/DelegateList.cs:69)
    UnityEngine.AsyncOperation:InvokeCompletionEvent()


    Exception encountered in operation UnityEngine.AddressableAssets.Initialization.InitializationOperation, result='', status='Succeeded' - Chain<GameObject,IResourceLocator>: ChainOperation of Type: UnityEngine.GameObject failed because dependent operation failed
    Dependency operation failed with System.Exception: Unknown error in AsyncOperation.
    UnityEngine.ResourceManagement.ChainOperation`2:OnWrappedCompleted(AsyncOperationHandle`1)
    DelegateList`1:Invoke(AsyncOperationHandle`1) (at Library/PackageCache/com.unity.addressables@1.1.7/Runtime/ResourceManager/Util/DelegateList.cs:69)
    UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1:<.ctor>b__26_0(AsyncOperationHandle)
    DelegateList`1:Invoke(AsyncOperationHandle) (at Library/PackageCache/com.unity.addressables@1.1.7/Runtime/ResourceManager/Util/DelegateList.cs:69)
    UnityEngine.AsyncOperation:InvokeCompletionEvent()
     
    Last edited: Aug 12, 2019
  3. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    You only cause one increment of ref count, so you only need to decrement once. So your adress.InstantiateAsync can be paired with Addressables.ReleaseInstance(refObject). No need to do adress.ReleaseAsset. That could be complicating things, but probably not. Are you loading anything else? If you are, that could be why some things are sticking around in memory. See https://docs.unity3d.com/Packages/com.unity.addressables@1.1/manual/MemoryManagement.html for more info.

    When you build for a platform, you are compiling shaders for that platform, and building them into the content. So if you build for android, then try to run that in the editor, it won't work. In general, android shaders won't run on a mac or PC. So if you need to test in play mode while platform is android for some reason, do it with Fast Mode. Otherwise keep your editor set to stand alone when doing play mode.

    That means one of the dependencies is failing, but without an error string to give you any info. Set a break point in AsyncOperationBase.cs Complete(). Depending on your IDE/platform you may have to copy the package into your Packages directory to get breakpoints to work.
    If you can track down what's failing, I'd love to know so that we can add better logging for that case.
     
  4. murat303

    murat303

    Joined:
    May 22, 2014
    Posts:
    38
    Thanks for the answers. I guess, textures remain in memory because of I pack the textures of prefabs together, according to the documentation; when I pack separately, textures are erased from memory, is it right?

    Also, I can only view correct memory usage in packed mode, in play mode; even if I delete prefabs, it seems textures always stored in memory.
     
  5. murat303

    murat303

    Joined:
    May 22, 2014
    Posts:
    38
    I'm always getting this error on opening unity; (Radio Pro asset and Adressable are conflicts)

    At each startup, I get this code into the comment line and so it takes a long time for Unity to open.

    Library\PackageCache\com.unity.scriptablebuildpipeline@1.5.2\Editor\CacheServer\Client.cs(440,35): error CS0433: The type 'InvalidDataException' exists in both 'CTNLayer, Version=2019.2.7146.36440, Culture=neutral, PublicKeyToken=null' and 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
     
  6. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Never seen that one before. We are using
    System.IO.InvalidDataException
    . It would seem that the Radio Pro package has opted to define their own thing called InvalidDataException. Assuming I understand correctly, that's a fairly bad practice on their part. Not much we can do about it. We're using a System provided class, and they are attempting to stomp that class.

    If Radio Pro does not come with source code, you are welcome to import hte scriptable build pipeline package and edit that line. Just throw some other exception. or log. or just delete it and hope you don't hit that error case.
     
  7. murat303

    murat303

    Joined:
    May 22, 2014
    Posts:
    38
    How can i import hte scriptable build pipeline package into the project? its on the packages section, out of assets folder.
     
  8. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    If you are using 19.3+ I believe there's a button in the Package manager (import? develop? something like that). If not, you can just copy from your package cache to <project>/Packages/com.unity.scriptablebuildpipeline/ From there you can edit the package to your heart's content.

    SBP is fairly stable at this point, so importing shouldn't cause a lot of pain to keep up with updates.