How to get find out if managed memory was allocated

Sorry for posting here, my question is not related to beta, but this forum is dedicated to profiling.
I’d like to know what API should be used to understand how much (managed) memory was allocated?

From what i saw there are a few different APIs, not sure which is the most accurate one:

*Please note that i would like this to be used from the context of an editor extension so this should work out of play mode.

1 Like

We do have the profiling tag on the forums which I and others in the profiler team follow :wink:

Anyways: as the naming in the APIs you mentioned indicates somewhat: those APIs give you what the Memory Profiler Module shows as “Total” value, i.e. Native + Managed.

If you want to get the managed memory only, you should be looking at

  • Profiler.GetMonoUsedSizeLong for how much is already occupied and how close you are to expanding the heap

  • Profiler.GetMonoHeapSizeLong for what the current cap for the heap is, where exceeding that cap will cause a GC.Collect and potentially heap growth, and also for what the OS sees in terms of managed memory.

Not that those are not going to report Native allocation from Mono itself, so no reporting on C# Type Metadata that would be allocated for Reflection stuff, only the managed heap.