Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

[Resolved] What is ref count 0?

Discussion in 'Profiler Previews' started by MadeFromPolygons, Apr 4, 2019.

  1. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    I have a ton of things showing up in the snapshot such as shaders that are not assigned to any material in the entire project.

    Speedtree8 takes up 24.7mb of memory and is biggest thing in the shaders part of snapshot, yet it says ref count is 0 and its not anywhere in the project.

    So what exactly does this mean and why is it taking up memory?

    And no there are no references to that shader in scripts either

    Ive marked this as a bug as it seems erroneous. Many other entries are like this, makes tracking down problems difficult as lots of things in the snapshot seem to not actually exist
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Did you profile in the editor? Because I recall another thread where someone else has the same issue and he/she was basically profiling in the editor, but in a build all these things were correct/stripped.
     
    MadeFromPolygons and MartinTilo like this.
  3. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,452
    To answer the question of what a Ref Count of 0 can mean:
    1) This object could be a root
    2) It might be left without a reference and is about to be GC collected or cleaned up by the next swipe of UnloadUnusedAssets
    3) It might be something that is neither tracked as an asset or managed memory and therefore is a leak

    that said, In the editor, things might be off. E.g. the asset database does not count as a root so things might be in memory due to the AssetDB.

    Also there was a bug related to this in preview 5, it landed in preview 6.
     
    MadeFromPolygons likes this.
  4. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    Just so your aware in the new preview this doesnt happen anymore :)
     
    MartinTilo likes this.
  5. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,980
    Also speedtree8 showed up as it was in my "Always Include" shaders list! Taking it out freed up a valuable 24.7mb and we dont use speetree anywhere so its free memory. Just in case anyone else is puzzled by the shaders part of the snapshot and why some things are there, check that list first!
     
    MartinTilo likes this.
  6. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    I have ScriptableObjects referenced by scene that stick around between scene loads while having 0 ref count, as seen here: https://forum.unity.com/threads/sce...ject-and-the-where-the-f-is-my-memory.790085/

    They are making a ton of assets linger around in memory, and I have no clue how I'm supposed to get rid of them. (UnloadUnusedAssets does nothing for them)
     
  7. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    It could also stick around in memory if it uses HideFlags, such as
    DontUnloadUnusedAsset
    , or if it's using DontDestroyOnLoad.
     
  8. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    How do you know if an asset is "flagged" with DontDestroyOnLoad? Does that propagate through a hierarchy of objects? If so, how do you revert that?

    Right now, the ScriptableObjects - and their references - sticking around between scene loads is a critical issue for us.
     
  9. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    I don't know where it's displayed in Unity's Memory Profiler, but the information is stored in the memory snapshot itself.

    In Heap Explorer (see my signature), every object that will not get unloaded automatically, is displaying a warning icon. If you select that object, it displays why in the property inspector.
    upload_2019-12-8_11-50-7.png
    This information is most likely also displayed in Unity's Memory Profiler somewhere.

    EDIT: I forgot to mention that you can also filter for "don't destroy on load" objects in Heap Explorer:
    upload_2019-12-8_11-54-39.png
    I guess Unity's Memory Profiler supports filtering these things too.
     
    Last edited: Dec 8, 2019
    Weiky and chrismarch like this.
  10. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    You're a life saver.

    For some reason, Unity's memory profiler was showing 0 ref, but your tool showed some. Really weird, but now everything unload properly.

    Lesson learned; don't use Unity's memory profiler.
     
    funkyCoty and Peter77 like this.