Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to retrieve a C# app's current memory usage?

I am automating some profiling tasks and want to log heap space and generation sizes real-time. The profiling API seems awfully complicated for what I need, and it seems to listen in on individual allocations and collections, which isn't that important to me. Profiling tools are a great help of course, but I was looking for a more flexible, programmable interface.

like image 214
Jeremy Avatar asked Jan 20 '09 12:01

Jeremy


People also ask

Can you recover refrigerant without a recovery machine?

In order to recover refrigerant without a machine, you must first obtain the Environmental Protection Agency (EPA) section 608 Technician Certification. Under this section, technicians are required to pass the EPA-approved test to earn Section 608 Technician Certification.


1 Answers

The term 'current memory usage' is a little loosely defined. Do you mean the working set? Whatever it means, you can use different properties such as VirtualMemorySize, WorkingSet, PrivateMemorySize, etc. from the process class to retrieve it.

long workingSet = System.Diagnostics.Process.GetCurrentProcess().WorkingSet64; 
like image 185
mmx Avatar answered Sep 21 '22 20:09

mmx