开发者

Finding the true memory footprint of a Windows application

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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜