I’m pretty new to memory profiling so I’ve never had to think too hard about these labels in the profiler, and I can’t seem to find a exact explanation for them online. What EXACTLY is the difference between these two?
I see that UT is always much smaller than TSMU, but what exactly does each refer to? I thought maybe UT is how much my actual game is using, separate from Unity and all of its components listed there, but adding them all up doesn’t match with TSMU either.
Basically what I’m really trying to figure out is, which one should I be worrying about? Is TSMU one of those cases where Unity will free up some of that if necessary? So if the end-goal device has 1GB of available RAM but TSMU is >1GB, it won’t necessarily crash, but if Used Total is >1GB, it definitely will?
Thanks for the question! I’ll explain memory stats here.
Unity Editor and Players internally use pools for all memory allocations. E.g. when allocating 16 bytes we ask system to allocate 4MB (in the Player) or 16MB (in the Editor) block and then all subsequent allocations use that memory. If block is full, we allocate another one and if it’s empty we return it to the system. This technique is used to improve performance and reduce fragmentation.
And also this makes stats a bit confusing.
Used Total - memory used right now if we don’t take pools and allocation headers data into account. Essentially it is sum of all internally managed allocations which are not freed yet. Profiler.GetTotalAllocatedMemoryLong is the Scripting API getter.
Reserved Total - is how much we took from the system. This includes all allocated memory including pools and extra allocation headers. In our case it is commit memory - we allocate on heap (reserve+commit). Includes Used Total. Scripting API equivalent - Profiler.GetTotalReservedMemoryLong.
Total System Memory Usage - total size of used (commit) memory by Unity process. This includes everything what is used by the process - Reserved Total + executable’s images (code and data). It is PrivateUsage of PROCESS_MEMORY_COUNTERS_EX on Windows.
Taking this into account in your case I would say that if Reserved Total >1GB player might definitely run out of memory on end-goal device. If TSMU>1GB system might page some some memory to disk, but that’s not guaranteed and it might make performance horrible. So it is always safer to have TSMU<1GB.
I would say TSMU is what should be mentioned as Required Memory in System Requirements for your game.
(That’s assuming you have TSMU data from the player.)
Interestingly on my device in question (a console), when profiling on the device itself, TSMU actually displays the full amount of memory I can possibly use, about 0.7gb of the system’s 1gb. Makes sense since unlike PC the console only has to worry about my game occupying that space and nothing else. That sort of clued me in that TSMU is the important number on PC too. But it’s nice to know what each label really means!
hi @alexeyzakharov , i was wondering whether the API Profiler.GetTotalAllocatedMemoryLong is with the same meaning as “Used Total” in profiler or this API refers to total memory used only by unity engine (which equals the value after "Unity: ", which is in the same row as “Used Total” on the profiler panel).
I took a snapshot at runtime by the API UnityEngine.Profiling.Memory.Experimental.TakeSnapshot(), and get the amount of memory of RenderTexture which rank 1st among native objects. RenderTexture takes 93.2 MB memory. And at the same time, I called the API Profiler.GetTotalAllocatedMemoryLong, it returns the value 66.22 MB, which is smaller than 93.2 MB.
Hi @jiwansu internally we use the same API for reporting the memory of a render texture to the snapshot. Are you perhaps looking at the whole RenderTexture category in the TreeMap instead of the individual items inside?
Actually, my point is that Profiler.GetTotalAllocatedMemoryLong() means “used unity” not “used total”,which is different from @alexeyzakharov 's point of view.
I was anticipating that you can confirm which one is correct.
And the render texture thing was just showed as my proof, not the key point.
I misunderstood the question as related to the RenderTexture
Profiler.GetTotalAllocatedMemoryLong() returns the memory used by Unity and tracked by Unity. The closest equivalent in memory stats area is “Unity:”. Which is - Unity: 38.7MB = Profiler.GetTotalAllocatedMemoryLong() + "untracked memory" - Profiler - FMOD - Video, where “untracked memory” are allocations done by some thirdparty libraries and OS.
This is messy, yes and right now we are fixing it with a new memory profiler.
Not at the moment - but we are working on a new api to query all available profiler stats in the Editor and Player.
(*We do have atm only undocumented UnityEditor.Profiling.ProfilerDriver.GetOverviewText(ProfilerArea profilerArea, int frame) which you can use in the Editor to get the whole memory stats text with ProfilerArea.Memory and parse - but not simple and clear getters for stats you mentioned).
@alexeyzakharov We are seeing something similar in a standalone development build: used 1.58GB, reserved 1.75GB, TSMU 1.42GB (lower than both?). It’s making it difficult to understand since I don’t know how these are supposed to relate. Built using 2018.4.2f1.
Should doing GC and Resources.UnloadUnusedAssets cause Reserved Total to fall? It isn’t in my tests. Or will that stay up at the previous highest level until Windows or something else tries to grab memory from somewhere?
And if we had some sort of memory leak, would that figure be included in the Used Total or Reserved Total or neither?
Resources.UnloadUnusedAssets might cause Reserved Total to decrease. As mentioned above Unity uses under the hood allocators which use larger memory pools for small allocations (e.g. 4MB blocks for allocations up to 1MB). The 4MB block is returned to the system only if it doesn’t contain any used small allocations within. Returning such block would reduce Reserved Total. Unfortunately memory fragmentation might happen if resources with different lifetime are loaded together. And then large block can be stuck for some time until major cleanup happens (e.g. loading new scene exclusively).
If you have a leak then both values should grow synchronously you can use any of those.
Would you explain me about the attached profiler status? I cannot understand why TSMU is so big. I cannot figure it out how to solve it. While move to the next scene, app gets down because of memory lack I guess. [Galaxy S9, Unity 2019.4.0f1]
Could you please capture detailed snapshot to see if there is more information available.
Also Memory Profiler can help with checking out native memory usage.
From the screen you’ve provided I can see that both native and managed allocations tracked by profiler can’t contribute to the system memory usage. Do you happen to use native plugins which allocate memory or similarly java level code which allocates?
I had a problem to get the below screenshot because app had been crashed. It was caused by IL2CPP. After changing to mono, app keeps alive anyway.
Please give me any comment about the screenshot status. Which one is real memory information that my app allocates? The total of Detailed is only 202.9MB, but TSMU says 3.28GB.
Both are real. The Total value is the Total value as tracked by Unity’s memory manager. The TSMU is the Total Memory that the OS reports as belonging to the Unity application; that includes Memory allocated in native Plugins that you might be using such as WWise, FMod, basically anything in your Plugins folder. The native Memory allocated by these plugins is not reported to Unity’s memory manager and therefore can’t be part of the Total number.