I am using AForge to capture video from a camera and display it in a WinForms PictureBox. AForge supplies an event that gets triggered on every new frame--so, for my camera, 30 times per second.
I'm finding that even when I am careful to dispose of the PictureBox's image, memory usage climbs rapidly (and in a weird pattern... see image below). My guess is that the event is being called more often than it can dispose of the bitmap, but I'm not sure.
Here is what I have inside the newframe
event. I'm using Monitor.TryEnter
per
- Video capture started
- Unknown event causes memory usage to increase
- Unknown event causes memory usage to stabilize
- Unknown event causes memory usage to increase
And that repeats. Note that if I change the TryEnter
timeout to a higher value, the stable memory usage periods get shorter.
If anyone can offer a solution for this memory leak, I would be very grateful. I did see a similar question here, but it wasn't really answered:
After adding GC.Collect()
: