title: What does it mean when Process.Start fails because "Insufficient system resources exist"
body: <p>I have a C# application which launches another executable using <code>Process.Start()</code>.</p>
  
  <p>99% of the time this call works perfectly fine. After the application has run for quite some time though, <code>Process.Start()</code> will fail with the error message: </p>
  
  <pre><code>Insufficient system resources exist to complete the requested service
  </code></pre>
  
  <p>Initially I thought this must have been due to a memory leak in my program - I've profiled it fairly extensively and it doesn't appear there's a leak - the memory footprint will still be reasonable even when this message failed.</p>
  
  <p>Immediately after a failure like this, if I print some of the system statistics it appears that I have over 600MB of RAM free, plenty of space on disk, and the CPU usage is effectively at 0%. </p>
  
  <p>Is there some other system resource I haven't thought of? Am I running into a memory limit within the .NET VM? </p>
  
  <p>Edit2:</p>
  
  <p>I opened up the application in SysInternals Process Explorer and it looks like I'm leaking Handles left and right:</p>
  
  <pre><code>Handles Used: 11,950,352 (!)
  GDI Handles: 26
  USER Handles: 22
  </code></pre>
  
  <p>What's strange here is that the Win32 side of handles seem very reasonable, but somehow my raw handle count has exploded waaaaay out of control. Any ideas what could cause a Handle leak like this? I was originally convinced it was Process.Start() but that would be USER handles, wouldn't it?</p>
  
  <p>Edit: </p>
  
  <p>Here's an example of how I'm creating the process:</p>
  
  <pre><code>var pInfo = new ProcessStartInfo(path, ClientStartArguments)
          {
              UseShellExecute = false,
              WorkingDirectory = workingDirectory
          };    
  ClientProcess = Process.Start(pInfo);
  </code></pre>
  
  <p>Here's an example of how I kill the same process (later in the program after I have interacted with the process):</p>
  
  <pre><code>Process[] clientProcesses = Process.GetProcessesByName(ClientProcessName);
  if (clientProcesses.Length &gt; 0)
  {
       foreach (var clientProcess in clientProcesses.Where(
                clientProcess =&gt; clientProcess.HasExited == false))
       {
          clientProcess.Kill();
       }
  }
  </code></pre>