I've looked through a few pages of similar inquiries, implemented most of the suggestions, but can't seem to find anything that's worked so far. Hopefully I'm not overlooking something glaringly obvious.
Right, so I'm using AForge.net to capture an image. It provides an event, which is triggered for each new frame received, which in my code looks like this:
private void videoSourcePlayer_NewFrame(object sender, ref Bitmap image)
{
framesRecieved++;
try
{
if (!stopCapturing)
{
if (pictureBox1.Image != null)
{
pictureBox1.Image.Dispose();
}
pictureBox1.Image = image.Clone(new Rectangle(0, 0, image.Width, image.Height), image.PixelFormat);
}
}
catch { }
finally { GC.Collect(); }
}
Memory usage is very stable so long as the window remains stationary, but as soon as I grab the window form and start moving it about, memory usage keeps going up. The reason I've been led to believe it might be related to the picturebox, is because as soon as I turn the "stopCapturing" bool to true, memory stops rising, even if I'm moving the window around the screen. "stopCapturing" is not used for anything else, and the event continues triggering as normal, the only difference is the image being displayed in the picturebox. I'm at a loss as to the cause, so any help would be appreciated.
PS: Not sure if it's related, but my workstation has 2 screens.