Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

iOS memory not released

Discussion in 'Addressables' started by pintianz, Nov 16, 2018.

  1. pintianz

    pintianz

    Joined:
    Mar 1, 2015
    Posts:
    25
    First just want to say that thank the Unity team for working on this system, I can see it being a very powerful tool to help automate and make easier to manage memory at run time.

    I've been testing out the addressable system and I found that memory usage does not decrease after I call releaseinstance on device on iPhone (the number of reference to the asset will go to 0 after the call, as can be been in the Addressable Profiler).

    Below is the script I use to test. I used Xcode activity Monitor instrument to see memory usage on device.
    - Scene begin 75mb
    - Load Minimap 145mb
    - Unload, gameobject instance destroyed, still 145 mb
    - Subsequent load is almost instantaneous. memory remain 145 mb

    If I understand the system correctly, shouldn't the addressable system monitor the active reference to an asset and release memory use when the reference goes down to 0? So why has this happened?

    Code (CSharp):
    1. public class AddressableManager : MonoBehaviour
    2. {
    3.  
    4.     // Use this for initialization
    5.     public AssetReference ar_mmap;
    6.     private GameObject go_mmap;
    7.     public GameObject loadingPlaceholder;
    8.  
    9.     void OnGUI()
    10.     {
    11.         GUI.Label(new Rect(0, 0, 100, 30), Time.time + "");
    12.         if (GUI.Button(new Rect(10, 10, 150, 100), "Load Minimap"))
    13.         {
    14.             if (go_mmap == null)
    15.             {
    16.                 ar_mmap.Instantiate<GameObject>().Completed += mmapInstantiateDone;
    17.                 go_mmap = loadingPlaceholder;
    18.             }
    19.         }
    20.         if (GUI.Button(new Rect(10, 120, 150, 100), "UNLOAD"))
    21.         {
    22.             Addressables.ReleaseInstance(go_mmap);
    23.         }
    24.     }
    25.  
    26.     private void mmapInstantiateDone(IAsyncOperation<GameObject> op){
    27.         if(go_mmap ==loadingPlaceholder) {
    28.             go_mmap = op.Result;
    29.         } else {
    30.             Addressables.ReleaseInstance(op.Result);
    31.         }
    32.     }
    33. }
    Screen Shot 2018-11-16 at 11.17.20 AM.png Screen Shot 2018-11-16 at 11.19.13 AM.png Screen Shot 2018-11-16 at 11.19.13 AM.png

    Unity 2018.2.11f
    Addressable system 0.4.8
     
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Without looking at your screenshots, the clear guess is that you are releasing the asset, but there is some other asset that is in the same bundle that you still have a reference to. Unfortunately that doesn't seem to align with you addressables profiler screenshot.

    Did you name your addressables group "minimap.prefab"? And is that screenshot of the iOS game, or is that done in play mode?

    -Bill
     
  3. pintianz

    pintianz

    Joined:
    Mar 1, 2015
    Posts:
    25
    Here is the Addressable asset window. Minimap.prefab is not the group name, it (along with 2 other prefab) is under the default local group.

    Screen Shot 2018-11-19 at 4.12.51 PM.png

    As seen in picture, this is an empty scene with only the script posted above in it. It references all 3 addressable asset (But so far the script can only instantiate Minimap). There are no other scenes in the build.

    The testing of memory usage is done on device (iPhone 5s) and measured via Xcode "Activity Monitor" instrument. As seen in images below (at difference times), memory never goes down after it Minimap prefab was loaded and notably all attempts in loading the asset after the first load finished instantaneously.

    Screen Shot 2018-11-19 at 4.11.28 PM.png Screen Shot 2018-11-19 at 4.11.44 PM.png Screen Shot 2018-11-19 at 4.11.53 PM.png

    I've disabled Assetbundle cache for the default local group. Could this be some kind of under the hood caching? Like do not release memory unless getting warning from platform? I really want to try AA on my actual project but I'm afraid to since I can't seem to properly manage memory with AA yet.
     
  4. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Given that setup, make sure you are either connecting the Addressables profiler to the running device, or running in Virtual or Packed mode in play mode. Then in the profiler, you'll see the counts on anything you've loaded form that bundle, such as the minimap, battlefield, or forest. If any of those still has a ref count, then the entire bundle will stay in memory. That's just how asset bundles work. If none of them have a ref count, then things should be getting unloaded.
    So either one of the other assets is causing the bundle to stay in memory, or we are most likely looking at a bug.
     
  5. pintianz

    pintianz

    Joined:
    Mar 1, 2015
    Posts:
    25
    Screen Shot 2018-11-20 at 8.43.55 AM.png
    The profiler screen shot on the original post was done in editor play mode with "Virtual mode" selected in Addressable window. And all ref count did return to zero after I click unload.
    I'm not sure how to hook up the addressable profiler to running on device for iOS since Unity seems to delegate to Xcode to install and run on device after build.

    So, verging in on bug territory?
     
  6. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
  7. mnapolillo

    mnapolillo

    Joined:
    Nov 30, 2017
    Posts:
    5
    Hi @unity_bill was this bug ever addressed? I appear to be having this issue in two separate projects, and it's causing crashes in one due to blowing up memory. I've gone through a bunch of methods and it appears to release the assets correctly in editor, but not in the iOS app. I'm using version 1.16.1 of the Addressables System, and I've tested this with both local and remote assets. Hope to hear back about this!
     
  8. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    We haven't been able to repro it with our setup. Can you please file a bug with Unity that has a repro project? When possible we try to jsut repro things based on descriptions here, but this case isn't working.