title: How do I find where my .Net app is leaking Windows handles?
body: <p>I've got a WinForms .Net app that runs over a lot of XPS documents (thousands) and during this run the number of handles (according sysinternals process monitor and task manager) increases by between 3-10 for each document. I heavily suspect that these are handles that are opened and not closed by the MS .Net XPS framework libraries but I can't track it down.</p>
  
  <p>Despite stepping through the code the handle count increases at different points during the same run. For example, one pass through the loop and the handle count will jump by 1 on one line and next time it might not, or it might jump by 2. So I suspect the XPS com components have a handle leak.</p>
  
  <p>Memory use is fine though, but if I keep exhausting handles like this then I'll crash the app and maybe the desktop.</p>
  
  <p>So far I have tried sysinternals process explorer to look at the handles but they are all marked as  with no more detail. Also used handle.exe from sysinternals and this does not show any significant different between a before, during and after snapshot.</p>
  
  <p>Any clues on how to track down where the handles are going? I think I'm going to have to simplify to a single threaded console app to test.</p>
  
  <p>Regards</p>
  
  <p>Ryan</p>