title: How To Troubleshoot Handle Leak in C# Windows Service
body: <p>I have a .NET 4 Windows Service written in C# running on Windows Server 2008, which when monitored with PerfMon, appears to consume 2,500 handles per hour. The "Handle Count" counter climbs ever upwards.</p>
  
  <p>When I look at the handles using ProcExp with the "Show Unnamed Handles and Mappings" option selected, there are thousands of Event and Semaphore handles listed. Most seem unnamed. I looked in the source code, and there are no explicit uses of AutoResetEvent or ManualResetEvent.</p>
  
  <p>The Private Bytes counter climbs and falls. I haven't watched the process for more than a couple of hours but will leave it being monitored overnight.</p>
  
  <p>The service runs on a remote server, so I can't directly attach a debugger, and will probably have to dump the process and analyse it with WinDBG or similar.</p>
  
  <p>Is it possible to locate one of the handles and find out what it points to and/or what might "own" it? If so how?</p>
  
  <p>In response to comments, here's a summary of what the service does.</p>
  
  <ul>
  <li>hosts some WCF services</li>
  <li>hosts an instance of Quartz.NET scheduler</li>
  <li>hosts a work item queue (quartz jobs push work items onto a queue rather than do long running work themselves)</li>
  <li>hosts a work item executor (work items are dequeued on a timer and executed away from Quartz)</li>
  <li>hosts a custom cache manager (which does a lot of ADO.NET work)</li>
  </ul>