views:

350

answers:

3

I am debugging some memory problems related to a managed application that we have. I was monitoring the application using perfmon when I got confused about the memory difference between the .NET Bytes in All Heaps and the Working Set reported in Process Explorer (Mem Usage column in case of Task Manager). The Bytes in all heaps counter displays the value as 15MB whereas the process working set is 78MB - a huge difference. I understand that some amount of memory would be consumed in the files loaded in memory, but still the numbers don't add up.

Any clues?

+1  A: 

This article gives a good overview of the various memory counters.

Working Set – This is a set of virtual memory pages (that are committed) for a process and are located in physical RAM. A working set is like a "currently/recently working on these pages" list

From your question description, it seems that you have approx. 63MB of unmanaged memory in use.

Mitch Wheat
A: 

Try and get your hands on FXCop. Have a look for the rule regarding the failure to call dispose on IDisposable types.

There are two main causes of memory leaks in .net, which are failure to call IDisposable (which is a technique that will call unmanaged destructors for P/Invoke code) and the second is failing to release references to objects, which causes them to not garbage collect. For instance if you are storing objects in a list, you may accidentally be keeping a reference to a list and thus an object still in memory.

Spence
Dude, IDisposable is just an interface, win32 handles are as of .NET 2.0 wrapper by the CriticalFinalizerObject which is guaranteed to be collected gracefully as long as the object is not being referenced.
John Leidegren
@John, not all types implement finalizers correctly. Many legacy types do not, as do many third party libraries. With this in mind it's possible to leak memory in your managed app
Spence
A: 

Rico Mariani's Performance Tidbits blog post Tracking down managed memory leaks (how to find a GC leak) does not directly answer your question re: Bytes in All Heaps and the Working Set, but it should help considerably with your task re:debugging some memory problems related to a managed application.

You may also want to review Two things to avoid for better memory usage and Three techniques for tracking down memory leaks due to undisposed objects.

All of the articles are quite old, but the information presented should still be helpful to you.

Grant Wagner