Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get application memory usage as shown in Task Manager?

I am trying to get the memory usage of my application but for some reason i am getting different size than in task manager

I am using:

enter image description here

Task manager shows that my application occupies 45mb , while when i pulling it in my code i get 85mb how can i get the same size as in task manager (without using wmi)

like image 705
atikot Avatar asked Dec 31 '14 11:12

atikot


People also ask

How do I view Task Manager memory usage?

While the Task Manager is open, you'll see a Task Manager icon in your notification area. This shows you how much CPU (central processing unit) resources are currently in use on your system, and you can mouse over it to see memory, disk, and network usage.

What memory is shown in Task Manager?

Memory — a continuously updated display of how much of your RAM is being used by each process and each user at the given moment. Total memory usage is shown in the column header.


1 Answers

Presumably you're looking at the wrong column in "Task manager" or using the wrong property in Process class..

I guess you're looking for WorkingSet64 not PrivateMemorySize64. PrivateMemorySize64 is the amount of virtual memory allocated for the process, not the physical memory. For physical memory use WorkingSet64.

Also, you need to call process.Refresh() before accessing any of the dynamic properties in process class as it is heavily cached.

process.Refresh();
_data.MemoryUsed = (process.WorkingSet64).ConvertBytesToMegabytes().ToString(CultureInfo.InvariantCulture);
like image 53
Sriram Sakthivel Avatar answered Oct 22 '22 03:10

Sriram Sakthivel