Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. The 2023.1 beta is now available for testing. To find out what's new, have a look at our 2023.1 feature highlights.
    Dismiss Notice

Bug Memory profiler ref count issue

Discussion in 'Profiler Previews' started by gsylvain, May 12, 2021.

  1. gsylvain

    gsylvain

    Joined:
    Aug 6, 2014
    Posts:
    91
    Hi!

    I am currently doing a memory optimization pass on our project. After using the unity Memory Profiler 0.2.9, I noticed something strange.

    1. main menu
    2. load a level
    3. unload a level
    4. Call Resources.UnloadUnusedAssets, WaitForPendingFinalizers, etc
    5. main menu
    6. take a memory snapshot

    In that memory snapshot, I can see quite a lot of objects having 0 reference but still lingering in memory. I'm trying to figure out what is holding up these objects. Since they have 0 ref, I'm at a loss here. After reading many threads, I've tried "Heap Explorer". This tool can see the missing ref that the unity memory profiler couldn't see (that would be something to look at on your end..)

    For the curious, my issue was that the addressable asset wasn't properly released. HeapExplorer shown my the name of the addressable asset and that's it.
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    1,910
    Hi and thanks for bringing up your issues here. I'm not 100% certain I get how Heap Explorer gets the references which the Memory Profiler fails to get but I'd like to dig a bit deeper into this as we should get that solved.

    Are you saying that Heap Explorer is showing you the references of the Addressable Asset (or AssetBundle) to the object that show as having 0 references in the package, or is it that Heap Explorer showed you the addressable asset name and therefor hinted better at what the issue is?

    If it is the former, that would definitely sound like a bug in the Memory Profiler package crawling code and we'd appreciate a bug report with a snapshot file for both Memory Profiler and Heap Explorer to be able to look into it.

    If it is the later, I'd like to know more details about how Heap Explorer was more helpful in this too.

    Also, just FYI, we're working towards a fix that would show connections that are currently not being reported (so neither tool can show them right now) between Asset Bundles and their Assets. Additionally, we have a fix going through backports that addresses a mistake in how the connections are being collected in the player when taking a snapshot, that (combined with the additional connection reports on ABs) should eliminate occurrences of 0 reference objects after GC.Collect and Resources.UnloadUnusedAssets. Those two changes should make issues like these disappear / make it easier to track down such connections (but they are connected to the Unity version and not the package version).
     
  3. gsylvain

    gsylvain

    Joined:
    Aug 6, 2014
    Posts:
    91
    Hi Martin,

    I had some objects having 0 references but staying in memory. The unity memory profiler couldn't hint me on what was holding them back.

    Heap Explorer display the addressable name as a reference, meaning that the asset hasn't been Released from the game code.

    That tiny but crucial info unblocked me and I've been able to successfully clear many unused assets from memory.

    It is so good to know that you guys are working on more changes and bugfixes for the memory profiler! I'll make sure to check often for new updates!

    Have a nice day,
    Guillaume

    HeapExplorer: https://github.com/pschraut/UnityHeapExplorer
     
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    1,910
    FYI: The fix for Native Connections being wrongly reported for Player builds is fixed in 2021.2.0a11, landed on 2020.3.12f1 and is still in flight to 2019.4.

    AssetBundle reference tracking to follow soon-ish (TM) but no clear landing pattern yet.
     
    Last edited: Jun 20, 2021
    gsylvain likes this.