2

I have a problem with an application that I wrote in .NET/C#. It consists of a server which manages a few other machines, and runs tests on them. It is a windows forms application. In order to run tests with proper error handling, for each machine I have two threads: one for running tests and one that pings it continuously. Each machine has a running queue, in which tasks are stored, tasks that will be run on that particular machine.
The issue is that after some time, when more than a few tasks are present in the queue, the memory it consumes(process explorer, task manager) gradually increases from about 50-100MB to 1.6-1.8 GB. At about this limit almost every transaction(file copy on share, remote WMI access) with the remote machines fails with either "Not enough storage" or "Out of memory". I tried some tools in order to localize the string and the closest I got was .Net Memory Profiler. That wasn't of great help, because the largest amount of memory was residing in "Private Data - Unidentified". This I'm guessing it's unmanaged data, because I can evaluate every other data(from my program) down to each string and int, and every instance of it.
Can anyone suggest a tool I can use in order to properly localize the leak and maybe fix it. It would help me a lot if I would know the DLL(from my app)/Thread that uses that memory, or at least if I can view somehow what is in that memory.

Note: A lot of posts are out there about the two exceptions: Not enough storage, and Out of memory. Most of them suggest increasing the IRPStackSize on the 'server' machine(in my case, clients). I have IRPStackSize of 50(0x32) on all of the machines, including the server.

EDIT
Regarding the comments: yes, I do maintain a log, but nothing strange happens. Using a memory profiler I discovered that my application, the .NET side uses about 20MB of memory when the unmanaged part is well over 1GB. With the help of WinDbg I found out what resides in that extra memory(in most of it). In order to access the machines and run different tests on them I use WMI, for which I have a wrapper. Everything I use is being disposed(using statements, and for some actually calling the Dispose method. Strangely though, the memory is filled with clones of this class. Does anyone know why a class would clone itself in memory.
Note: the rate at which the memory usage increases in about 5MB/s, so it's not really over a long period of time. I also wonder why it is not being freed by the garbage collector. I am using C# classes to work with WMI, not COM, nor unmanaged code. Also, among the objects on the heap I see a lot of data belonging to wmiutils, CWbemError. Oddly enough, google doesn't even know the word(no results for CWbemError)

Cristi M
  • 446
  • 4
  • 13
  • already had a look into http://www.codeproject.com/Articles/19490/Memory-Leak-Detection-in-NET ? its a bit of work, but increasing the IRPStackSize wont help you alot if it consumes more and more memory – Najzero Jun 10 '13 at 12:21
  • I attached windbg to the process and it has a lot of CLR exceptions with code e0434352. Now i am trying to debug it and see where exactly is the problem. Another issue is that .loadby sos fails, does not find sos.dll. So besides issues with the application, I also have issues with debugging:). I will take a look at the codeproject article as well.... – Cristi M Jun 10 '13 at 13:56
  • Are you maintaining a log? – MSRS Jun 10 '13 at 14:01
  • "Not enough storage" is a low-level Windows error, a long distance from managed code. It indicates that the kernel memory pool has a leak. You could be leaking handles, easy to see in Taskmgr.exe by adding the Handles, USER Objects and GDI Objects to the columns. If that doesn't pan out then you've got some sick unmanaged code running on that machine. Yes, hard to find it. – Hans Passant Jun 10 '13 at 14:24
  • Are you attaching event handlers to the forms? If yes, then can you look at the amount of GDI objects? The leak could be stemming from the event handlers not being removed. – Vinay Pandey Apr 23 '15 at 09:41

0 Answers0