How to see memory allocation in this .NET application?

I need to check how much memory is allocated on the heap. Is there a way to get this value programmatically using C #?

I know about System.Runtime.InteropServices.Marshal.SizeOf(...) , but that only tells me the size of the object.

+4
source share
2 answers

Using a PerformanceCounter , you can request "# Bytes in all heaps" from your own process and even other processes.

Use the .Net CLR Memory category to see the many counters available.

You should see the difference in system load between PerformanceCounter and GC.GetTotalMemory proposed by John Skeet.

+5
source

Does GC.GetTotalMemory do everything you need?

(Note that SizeOf only indicates the size of the marshalling - not necessarily the size in memory.)

+4
source

All Articles