views:

83

answers:

1

I'm trying to get a program I'm writing (in F#, though I would imagine the answer here is the same for any CLR language?) to report on its own memory usage (so I can get an idea of how much I'm stressing the machine, compare sizes of different workloads, and evaluate the effect of any optimizations I do in the hope of saving memory).

The good news is, class Process has plenty of stats available. http://msdn.microsoft.com/en-us/library/system.diagnostics.process_members.aspx

However, there are very many different memory usage figures. Here's four from a test run:

Peak paged memory size    13,492,224
Peak virtual memory size  138,661,888
Peak working set          14,188,544
Private memory size       13,492,224

And there are several others available. What's the difference between them? Which ones are the best answers to "how much memory did the program use on this run it's just finishing now?" And do the same figures have the same meaning on Mono on Linux or MacOS?

A: 

It seems the best figure, for a program trying to monitor its own memory usage, is GC.GetTotalMemory.

rwallace