I've written an application making use of WPF Toolkit charts. I've got a timer that updates the charts every so often. After my app runs for a while I noticed that it's consuming a bunch of memory. After taking a couple of process dumps
(via adplus.vbs) I believe the problem is that all of my charts which I think I'm no longer using are still being referenced. Maybe I'm doing something wrong and not releasing them correctly, but my initial guess would be that I am releasing them correct.
Basically I've got a content control and when my periodic timer goes off I create a new chart and set my content's control Content property to the new chart. This is all that I should need to do, correct? Below is a code snippet:
Chart chart = new Chart();
chart.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
chart.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
this.Content = chart;
Here is an output from !gcroot indicating what's holding onto the no longer needed charts:
0:000> !gcroot -nostacks 01786bd0
Note the first chart (01c7b550) I'm guessing is that chart currently active in my UI. That is holding a reference to a ResourceDictionaryDispenser which eventually seems to have a reference to the chart I no longer need. What's up with this?
How do I fully get the chart I'm replacing to not be referenced by anything?