C# – Causes for web service memory leak

.net-3.5c++memory-leaksweb-services

We have a web service that uses up more and more private bytes until that application stops responding. The managed heap (mostly Gen2) will show some 200-250 MB, while private bytes shows over 1GB. What are possible causes of a memory leak outside of the managed heap?

I've already checked for the following:

  1. Prolific dynamic assemblies (Xml serialization, regex, etc.)
  2. Session state (turned off)
  3. System.Policy.Evidence memory leak (SP1 installed)
  4. Threading deadlock (no use of Join, only lock)
  5. Use of SQLOLEDB (using SqlClient)

What other sources can I check for?

Best Solution

Make sure your app is complied in release mode. If you compile under debug mode, and deploy that, simply instantiating a class that has an event defined (event doesn't even need to be raised), will cause a small piece of memory to leak. Instantiating enough of these objects over a long enough period of time will cause all the memory to be used. I've seen web apps that would use up all the memory within a matter of hours, simply because a debug build was used. Compiling as a release build immediately and permanently fixed the problem.