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

MemoryProfiler: zero RefCount

Discussion in 'Profiler Previews' started by dotsquid, May 30, 2019.

  1. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    First of all, thanks for this amazing tool.
    I wonder why some RefCounts are zero? How is that possible?
    upload_2019-5-30_13-27-38.png
    (sorry for the highlighted line, couldn't deselect it)
     
  2. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    973
    Presumably because there are no managed references to them, only unmanaged.
     
    MartinTilo likes this.
  3. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    Wellp, now I feel awkward I did not figure that out by myself :/
    Thanks for the hint!
     
  4. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,458
    Yes. These are, however, also things to look at regarding potential memory leaks.
    Now, they might be about to get cleaned out by the next Resources.UnloadUnusedAssets swipe, or within the next 1 or two scene unloads (Assets attached to scenes stick around after the scene is unloaded until the next one is unloaded). Something worth to investigate for you. Diffing snapshot before and after such unload operations should allow you to see, if this is getting removed as expected.
    Seeing as this is a ScriptableObject, which you might have forgotten to call Object.Destroy() on so maybe the managed wrapper has since been GC collected, but the native memory still lingers. Similar issues tend to blind side people when using RenderTextures.

    General Advice: Remember to Call Destroy on UnityEngine.Objects that you created yourself.
     
    dotsquid likes this.
  5. dotsquid

    dotsquid

    Joined:
    Aug 11, 2016
    Posts:
    224
    What's the reason of such behaviour? Why those assets are not released right after their scene is unloaded?
     
  6. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    973
    Because UnloadUnusedAssets is a slow blocking operation and you can trigger it manually if needed, anyway.
     
    dotsquid likes this.
  7. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,458
    Yes, also, because you may be loading a scene after the current one is unloaded, that reuses the same asset. loading and unloading the asset then results in needles loading time.

    That said, if you don't care for that optimization because most of the assets are unique and you're more worried about raising the high water mark of your memory usage, you can load an empty scene in between and/or call Resoruces.UnloadUnusedAssets in between of scene loads and take the unnecessary load time hit for any assets that might be present in both scenes.
     
    dotsquid likes this.