I'm working a windows .Net C# WPF application.
The application displays video frames in addition to some additional analytic data in a canvas.
The app is processing a frame rate of about 15 frames per second.
Processing is completed on separate thread.
The processing thread sends callbacks when analysis is completed and the display is to be updated.
I've noticed some significant memory growth (leaks) as I run the application over a period of time.
After running for a couple of hours, the application's memory footprint grows to a size of over 200MB.
In order to try to track these leaks, I'm using red-gate's ANTs Memory Profiler.
Based on the results I've captured, it appears that my dispatcher.BeginInvoke() calls are
the source of at least some of the leaks. The dispatcher.BeginInvoke() is required as I am
updating the UI from a different thread (one other than the UI thread).
Here is a sample code block:
// Clear the previous points
SolidColorBrush pointBrush = new SolidColorBrush(Colors.Cornsilk);
foreach (var point in points)
Ellipse ellipse = new Ellipse()
Width = 4,
Height = 4,
Fill = pointBrush
Canvas.SetLeft(ellipse, point.x * XScaleFactor);
Canvas.SetTop(ellipse, point.y * YScaleFactor);
SolidColorBrush boundingBrush = new SolidColorBrush(Colors.Bisque);
Rectangle boundingBox = new Rectangle()
Width = width,
Height = height,
Stroke = boundingBrush,
StrokeThickness = 1,
Canvas.SetLeft(boundingBox, xMin * mImageXScaleFactor);
Canvas.SetTop(boundingBox, yMin * mImageYScaleFactor);
How do I figure out what is really going on here and how do I resolve this issue?