title: AForge.NET Leaks Handles
body: <p>i have a program i am working on, we found a memory leak quite some time ago, and have managed to solve the inital issue, however now we have found that our AForge.net video player is leaking Handles, we are disposing the controls but for some reason the handles are never released.</p>
  
  <p>the window that uses the AForge.Net video controls is a bubble that pops up and tells the user some information, and if a video source is available, its displayed, we have found that if we dont provide a video source, the handles are released correctly, however anytime we show a video stream, the handles are not release and eventually we hit 15,000 handles and the application crashes, telling us AForge.NET is the faulting module.</p>
  
  <p>the disposing code is below.</p>
  
  <pre><code>if (videoSourcePlayer != null)
  {
  if (videoSourcePlayer.VideoSource != null)
  {
  // clearing the event subscription
  videoSourcePlayer.VideoSource.PlayingFinished -= VideoSource_PlayingFinished;
  
  // remove refernce to video source
  videoSourcePlayer.VideoSource = null;
  
  }
  
  if (videoSourcePlayer.IsRunning &amp;&amp; _openVideoAlarmsCount &lt; 1)
  {
  videoSourcePlayer.Stop();
  }
  
  if (videoSourcePlayer.IsRunning)
  {
  videoSourcePlayer.VideoSource.Stop();
  }
  
  videoSourcePlayer.Click -= videoSourcePlayer_Click;
  
  // dispose video player
  videoSourcePlayer.Dispose();
  videoSourcePlayer = null;
  }
  </code></pre>
  
  <p>videoSourcePlayer is the name of the control on the WinForm , i beleve its being disposed correctly, but no matter what i try i cannot get it to release the handles correctly, i cannot share to much of the code, but i can try to answer any questions that anyone has that may help in correcting the issue, or atleast identifying the bug.</p>
  
  <p>note: we are using Winforms + .NET 3.5 SP1 and the latest AForge.net from <a href="http://www.aforgenet.com/news/2012.02.23.releasing_framework_2.2.4.html" rel="nofollow">http://www.aforgenet.com/news/2012.02.23.releasing_framework_2.2.4.html</a></p>
  
  <p>Thank you in advance for the help!</p>