I have an application (winform exe) that I run several times. Does this mean that I have share assemblies or does each instance have its own copie of the assemblies? When I run the app, it uses about 30MB (in task manager) and when I run another copy of the app it uses another 30MB.
How do I work out how much of the memory it is using and if I can reduce the over usage of memory if I run several instances?
Regards
JD.
It’s complicated.
Start by reading my recent article on virtual memory.
http://blogs.msdn.com/ericlippert/archive/2009/06/08/out-of-memory-does-not-refer-to-physical-memory.aspx
OK, now that you have some understanding of how virtual memory works, you can understand how the operating system loads DLLs into memory. Suppose you have two processes that both need a particular page of Foo.DLL. The operating system will load that page into physical memory ONCE and then map that physical page into the virtual space of both processes. So the amount of physical memory that is being used is, say, a 4KB page. But that 4KB shows up in BOTH processes. It is likely that most of your 30MB is shared physical memory.
The way to find out is to be more sophisticated about your use of task manager. You want to add some columns there and look at both “Working Set” and “Private Working Set”. “Working Set” is the total number of pages, private AND shared, currently in use by that process. “Private Working Set” is the number of those which are not shared.
To lower your memory usage — well, first off, start by understanding why you care. Machines have plenty of memory these days and 30MB is a relatively tiny amount of memory. Unless you can find a compelling customer-focused reason to work on this, then work on something else, like making your program faster or adding more features. Assuming that you do have a reason to care, get yourself some tools — particularly, memory profilers. The .NET memory profiler can tell you where all your allocations are and how big they are.