Chart Destruction, Memory, and Garbage Collection

Jan 26, 2010 at 8:35 PM


I have come across some scenarios where, when my dataset is large (~ (4 linecharts * 250K points) + 50K markers of Ellipses, Rectangles and or TextBlocks), closing my UserControl which holds this plot does not readily free the memory used by this plot.  If I wait long enough and so some other activity, the GC finally kicks in and cleans up.  My main issue is that this plot of mine may be opened, closed, reopened repopulated with new data, then closed again, and so on.  Doing this multiple times in succession, before the GC kicks in, runs me into OutOfMemoryExceptions.  I have gotten to the point where, in my Unloaded event (or Closing event, if in a Window), I have method like the following which forces DDD to clean up stuff.

    private void DestroyPlot() {
	markerChart.DataSource = null;
	markerChart.ItemsSource = null;
   plotter = null;

Am I expected to do stuff like this?  Or would it be better to explicitely call GC.Collect() instead?




Mar 1, 2010 at 2:31 PM

Just wondering if anyone has had issues with lingering chart objects, or perhaps I am doing something wrong that requires cleaning up the way I have described above.