Where did my memory go? a large number of personal bytes

I have a WPF application that, among other things, displays a lot of images, large and small. My problem is that the application uses a lot of memory, and I cannot figure out where it comes from.

In the script, emphasizing the application, I get this graph in perfmon:

http://www.imagechicken.com/uploads/1244548604007097000.jpg

The big black line is Process \ Private bytes, and the remaining lines are the counters of CLR make-ups (pink - Total commit bytes)

In the numbers on the graph:
Private bytes ~ 350 MB
Committed bytes ~ 100 Mb

I dug many times using WinDbg and other tools, and they all report that the managed stack is behaving (! Eeheap reports a total managed stack of about 100 MB)

I shoved with applications like LeakDiag, LDGrapher, but did not find anything.

So finally, to my question, how can I find out where my memory goes?

Even at startup, the application uses 100 MB in fixed bytes, but 190 MB in private bytes.

Literature:

I read a lot about this, among others, on wonderful sites:

Tess Ferrandaise: http://blogs.msdn.com/tess/archive/2009/02/27/net-memory-leak-reader-email-are-you-really-leaking-net-memory.aspx

Rico Mariani: http://blogs.msdn.com/ricom/archive/2004/12/10/279612.aspx

MSDN mag: http://msdn.microsoft.com/en-us/magazine/cc163528.aspx

+7
debugging memory-leaks wpf
source share
5 answers

I had a similar problem in a WPF application, and used UMDH for tracking , in which my own memory was allocated. (Note that it is usually useful to set _NT_SYMBOL_PATH to get good stack traces from OS components.

Logs showed that almost the entire amount of memory is allocated in the video driver. I found that the driver was out of date for over a year; I installed the latest version from the manufacturerโ€™s website and fixed the problem.

+4
source share

Just because your application uses a lot of memory does not necessarily mean that you have a memory leak. From the information in your question, itโ€™s hard to say what might be wrong.

When resolving a managed memory leak error using WinDbg, I do the following:

  • Get an overview of heap usage with !eeheap (this reports heap usage, not the stack, as you mention - each stack has a default size of 1 MB, so if you haven't changed this, you can use 100 MB on the stack)

  • Do !dumpheap -stat to find out what is in the heap. Most likely, if you have a memory leak, then the culpable types (s) will be among the best consumers. To understand how heap usage is evolving, you can resume your application, break it up a bit, and then repeat the !dumpheap -stat .

  • If you find any types with a large number of instances besides those that would be selected, list them with !dumpheap -mt <MT of type> . This list lists all instances of a particular type. Select random instances and check the roots with the !gcroot . This will tell you what keeps these examples alive. If there is no root, these instances will be collected at some point.

UPDATE to respond to your comments:

A managed heap is only part of the memory area of โ€‹โ€‹a managed application. Remember that a .NET application is really an application inside another application - a host process that loads the CLR, which in turn loads your application. Therefore, before your application starts using any memory, the CLR has already taken a fair share. Besides the fact that .NET applications store both MSIL code and JIT-compiled code as part of the print foot. The CLR also takes up space for various types of accounting (for example, the CLR creates two additional AddDomains for internal use).

The numbers you give do not hit me like the top, but since I do not know your application, it is difficult to say whether they are excessive.

100 MB on a managed heap might be fine, depending on what your application is doing. Have you checked a bunch? And if so, what did you find?

+3
source share

Download MemProfiler from Scitech. It has a 14 day trial.

The issue you are reporting is often related to views / resources that cannot be removed due to the root in the heap. A common reason is the reluctance of event handlers.

+1
source share

You may like to read this article in the latest MSDN journal . It details how to use VADump to understand where process memory is dedicated.

You can download VADump here: http://go.microsoft.com/fwlink/?LinkId=149683

To break up a managed heap, you can try the memory profiler. I personally like JetBrains dotTrace .

+1
source share

One answer: it integrates ResourceDictionaries too much (WPF thing)

Details To be able to see the design during development in Blend and VS, we used to combine our vocabulary of thematic resources on most xaml pages. This caused a copy of all the resources that need to be downloaded for each control, here you can read more information: [WPF students] [1]

So, the only place I combine them is App.xaml.cs:

 <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/Company.Themes;Component/AppTheme.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> 

Results: (launching the application through some pages with an automatic graphical interface)

Before:

  • After downloading the application: 63 MB
  • After using the application: 177 Mb

After:

  • After downloading the application: 53 MB
  • After using the application: 97 MB

I will send more answers when I find them! (I thought it would be easier if readers saw that my answers as separate answers instead of replies to comments are okay?)

[1]: ref: http://groups.google.com/group/wpf-disciples/web/wpf-and-xaml-coding-guidelines?pli=1

0
source share

All Articles