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.

Question "Profiler Used Memory" on non-development player

Discussion in 'Editor & General Support' started by PhaneV, Nov 16, 2022.

  1. PhaneV


    Aug 3, 2015

    I'm working on a medium sized project and I'm looking into optimizing the game's memory footprint.
    Unity is 2021.3.11f1.

    While doing so, I used ProfilerRecorder
    I'm tracking these stat names: "System Used Memory", "Total Used Memory", "Total Reserved Memory", "GC Used Memory", "GC Reserved Memory", "Profiler Used Memory", "Profiler Reserved Memory",

    What I've noticed is that on release builds, the values displayed for "Profiler Used Memory" and "Profiler Reserved Memory" are quite high. (hundreds of MBs)
    I'm trying to understand if those numbers are reliable. They don't look reliable, because a build with "development" off shouldn't do that. It's worth mentioning that the numbers returned by these stats keep changing as you progress through the game, the same way the "GC" stats do. So they seem correlated to the actual memory used.
    Worth mentioning that "System Used Memory" and "Total Used Memory" return accurate values that double-check with the OS-reported memory usage.
    Another worthy mention is that this behaviour can be noticed on non-development builds only.

    One thought is that by calling "ProfilerRecorder.StartNew" at least once, it auto-starts the profiling code. But is that code supposed to be there at all, when "development" is off? Stats like "GC Allocated In Frame" don't display anything on release, so those are off.
    Another one is that "Profiler.enabled = false" doesn't actually turn it off.

    It really depends on the way the profiler is implemented, and that's something that I don't know how to check.

    Did anyone else notice this behaviour?
    Anyone from Unity care to take a look?

    alexeyzakharov likes this.
  2. PhaneV


    Aug 3, 2015
  3. alexeyzakharov


    Unity Technologies

    Jul 2, 2014
    Hi @PhaneV,
    thanks for the question!

    I've checked the code and I believe this is a bug.

    Some explanation:
    Profiler uses a dedicated memory allocator in development builds and Profiler * Memory returns the size of that allocator. However in release builds the general purpose allocator is used (as profiler is only represented by ProfilerMarker and ProfilerRecorder implementations there is no need in overhead of a dedicated allocator). And thus in release builds Profiler * Memory returns same value as Total * Memory

    Let me know if you would like to file a bug to track the fix progress or I could do that on your behalf.