Why does Process.PrivateMemorySize64 /1024 not match what Windows Task Manager Memory (Private Working Set)?
Asked Answered
B

3

8

Why does Process.PrivateMemorySize64 /1024 not match what Windows Task Manager Memory (Private Working Set)?

There seems to be a big (~ 30%) difference. Plus the value doesn't update frequently like task manager.

Calling _process.Refresh() doesn't help.

Benevento answered 23/10, 2014 at 9:2 Comment(2)
see here(itwriting.com/dotnetmem.php). This may help you find out the memory-issues on .Net. The memory printed in TaskManager is not the actual used memory of your application.Pope
They are drastically different numbers, virtual memory vs physical memory.Kerley
I
5

You are looking at different things.

The PrivateMemorySize64 property from the Process class is the equivalent of the Private Bytes performance counter. It represents the total amount of private memory allocated for the associated process that cannot be shared with other processes. Private bytes are not only physical memory, but also paged files etc.

On the other end the Private Working Set tracks a subset of the private bytes above, which represents only the physical memory that a process is using and can't be shared with other processes.

Imprecision answered 23/10, 2014 at 9:15 Comment(0)
F
3

The PrivateMemorySize64 represents all your private memory, not just the private working set, which is the amount of private memory that is currently not paged to disk.

In case you would like to know the total size of your process, you should use the VirtualMemorySize64 property instead. It accounts for all memory allocated by your process regardless of whether that memory is paged or on RAM. This is useful for example to know if your 32 bit process is getting close to 2GB of Virtual Size (process address space), which is normally the limit for a 32 bit process (unless one uses the /3GB option on a 32 bit Windows or the application runs on a 64 bit version of Windows and is large address aware).

Fiction answered 23/10, 2014 at 20:44 Comment(0)
F
0

I think this is what you are looking for

var ram = new PerformanceCounter("Process", "Working Set - Private", processName, true);
var ramUsage = Math.Round(ram.NextValue() / 1024 / 1024, 2)
Console.WriteLine($"{ramUsage}");
Fibriform answered 30/11, 2022 at 4:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.