For debugging purposes, I have written this little static method:
public static long CheckMemory(long maxMemorySizeBytes)
{
GC.Collect();
GC.WaitForPendi
VirtualMemorySize measures all of the virtual memory that your process uses. Which includes the pages shared by all other processes on your machine. Which in a .NET program includes the operating system, CLR, jitter and the ngen-ed Framework assemblies.
Diagnostic tools - Displays a live graph of your application’s Private Bytes metric. Private Bytes is a measure of the total amount of memory that a process has allocated, not including memory shared with other processes.
In Task Manager, by default, you see the "private working set" memory, which is the amount of memory used by a process that cannot be shared among other processes.
So:
If you want to get an idea of how much memory you're using, retrieve the VirtualMemorySize, Working Set and Private Bytes for a process.
If you add up all of the processes' VirtualMemorySize, you'll likely find it adds up to way more memory than you actually have. That's because those memory-mapped files, EXEs, DLLs, etc. can be shared among processes; and the same physical page in RAM can be accessed in more than one's process's address space at once.