[Resolved] What is ref count 0?

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

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.

2 Likes

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.

1 Like

Just so your aware in the new preview this doesnt happen anymore :slight_smile:

1 Like

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!

1 Like

I have ScriptableObjects referenced by scene that stick around between scene loads while having 0 ref count, as seen here: https://discussions.unity.com/t/768353

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)

It could also stick around in memory if it uses HideFlags, such as DontUnloadUnusedAsset, or if it’s using DontDestroyOnLoad.

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.

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.
Screenshot 5258468--525770--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:
Screenshot 5258468--525779--upload_2019-12-8_11-54-39.png
I guess Unity’s Memory Profiler supports filtering these things too.

2 Likes

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.

2 Likes