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!