3

I've run into a few OutOfMemoryExceptions with my C#/WPF application and I'm running into some confusing data while attempting to profile the memory usage.

When the app is typically running, Windows Task Manager shows the memory usage as somewhere around 34 MB (bounces around slightly as objects are created and garbage collected). When I run memory profiling applications such as CLR Profiler and dotTrace Memory, they show the total memory usage at around 1.2 MB.

Why this huge discrepancy? What does Task Manager see that these profilers do not?

UPDATE: I added some diag code to my application to print out various memory information every so often via the Process class.

While running my app, I set up a rule in DebugDiag to perform a memory dump in the event of an exception. I forced an exception and the memory dump occurred. At this point, the memory usage of my app (as shown by task manager) jumped from 32 MB to 145 MB and remained there.

You can see this jump in the table below (WorkingSet64). I'm still trying to make sense of all the types of memory info provided by the Process class. How would an external application make the working set of my app grow like this?

Link to data table here.

3
  • 2
    CLR Profiler doesn't show unmanaged memory. The process itself and the runtime use memory. You can use vadump blogs.msdn.com/b/maoni/archive/2004/11/08/… to see more specific how memory is consumed or use the briljant process explorer from techne/sysinternals technet.microsoft.com/en-us/sysinternals/bb896653
    – rene
    Mar 16, 2011 at 14:47
  • 1
    Why are you getting out of memory errors with such a low usage? Perhaps your problem is actually memory corruption. Mar 16, 2011 at 14:57
  • I'll take a look at the other profilers, thanks. The platform the app is running on is a small panel PC with only 512 MB of memory. It's also a flash-based hard drive, so paging is disabled. There are other apps running concurrently, so I'm trying to get a full understanding of memory usage.
    – BabaBooey
    Mar 16, 2011 at 15:04

2 Answers 2

9

Using some of the diagnostics tools suggested here, plus the ANTS memory profiler (which is so money) I found the source of the leak.

  1. WPF Storyboard animations leak under .NET 3.5
  2. The WPF BitmapEffect class can cause leaks. The alternative "Effect" class fixes the leak. Link, Link
  3. XAML Merged ResourceDictionaries can cause leak. Link, Link
  4. The "Working Set" memory footprint of an application (memory shown by task manager) is not a good indication of your process' footprint. Outside applications can influence this. Link

The memory profiling tools helped me find that the leaks were mostly in unmanaged code, which made it a real pain to track down. Dealing with these leaks, plus a better understanding of Windows memory (private vs working set) cleared things up.

6

Prcess Explorer and VMMap, both part of the Sysinternals Suite by Mark Russinovich.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.