1

Our C# .NET application experiences "OutOfMemoryException"s. They occur on random function calls, often when images need to be drawn (System.Drawing.Image.get_RawFormat) or threads need to be created (System.Threading.Thread.StartInternal).

Needless to say, I am unable to reproduce the crashes on my development machine. I acquired a heap snapshot of a crashed application, and I had a look at another crashed instance using the Process Explorer.

For example, in one instance, there are 380M heap RAM (that seems OK), 7758 handles (which seem rather high), 2245 USER- and 1798 GDI objects).

Using the nice software "Process Hacker" I was able to obtain a "handle type histogram". This showed 4181 "Section" handles, 2834 "Event" handles and 420 "Thread" handles. The "Section" handle count is much higher than what I find on my development machine.

I reviewed the question "What can cause section handle leaks?", but unfortunately the answers did not help me. We do not use memory-mapped files or IPC (at least not directly), and we do not use the function mentioned in this post.

I tried to memory profile the application, but did not find any obvious or major memory leak. I added a hook to the application that runs GC and prints memory information/handle counts, but using this hot key I was not able to reproduce the leak, even in the production setting.

We are using third-party software that might also cause some of the problems (DevExpress controls and other components).

At the moment, I am rather clueless and would like to ask you for your advice. What can I review or examine? How can I proceed to track down the problem? Thanks for any help!

Community
  • 1
  • 1
Matthias Wuttke
  • 1,982
  • 2
  • 21
  • 38
  • I know it might be too late to asking here, but any progress on this? I got the similar issue as yours. – Shawn Dec 22 '16 at 01:45

1 Answers1

1

For situations like this, an approach that works is to start commenting out sections of the repeating logic. Start by removing most of it, and check for leaks. If the leak disappeared, start uncommenting the code again piece by piece until the leaks start back up. It's annoying, but it can really help you nail down the culprit when the other options aren't present.

Max
  • 11
  • 1