System.Diagnostics.Process is giving me nothing?

Hi guys.

I’m currently working on a little memory profiler and I’m running into some problems:

Here’s my current code:

var process = Process.GetCurrentProcess();
UnityEngine.Debug.Log(process.Id + " : " + process.ProcessName);
var pagedMemorySize = process.PagedMemorySize64;
UnityEngine.Debug.Log(pagedMemorySize.ToString());

Sadly the second output prints “0” which is… a little confusing. The description says that I should get the allocated memory of the process, which should the current process itself (either unity itself in editor mode or my game if I run it as standalone). So what could be wrong that I get zero memory?

Also tried System.GC.GetTotalMemory but the numbers are very confusing and I couldn’t figure out how the numbers are calculated.

Thx for help!

        long startBytes = GC.GetTotalMemory(true);

        ... insert your code that does various memory intensive work here....

        long endBytes = GC.GetTotalMemory(true);
        Debug.Log(String.Format("Starting with {0:N} Megabytes allocated.", startBytes / 1024 / 1024));
        Debug.Log(String.Format("Memory allocated for our data is {0:N} Megabytes", (endBytes - startBytes) / 1024 / 1024));

Hm ok, seems like I have missunderstood the GetTotalMemory function then. Thanks for the hint, I’ll try this one out.