0

I draw chart with DynamicDataDisplay.ChartPlotter and each time I redraw the chart memory increase. So when I have redraw 200 times my chart memory of my app increase to 200mo in memory.

I tried to GC.Collect() manually but nothing change.

    private ChartPlotter _courbeChartPlotter;
    public ChartPlotter CourbeChartPlotter
    {
        get { return _courbeChartPlotter; }
        set
        {
            _courbeChartPlotter = value;
            RaisePropertyChanged();
        }
    }

    private static ListPointD3Cs _listeX = new ListPointD3Cs { new Point(0, 0) };
    private static EnumerableDataSource<Point> dsX = new EnumerableDataSource<Point>(_listeX);
    private int nbPoint = 0;

    public void TakeMeasureTest()
    {
        nbPoint++;
        _listeX.Add(new Point(nbPoint, GetRandomNumber(-1, 1)));
        InitDotsCourbe(out dsX);
        TraceCourbe(dsX);
    }

    public void InitDotsCourbe(out EnumerableDataSource<Point> dsX)
    {
        dsX = new EnumerableDataSource<Point>(_listeX);
        dsX.SetXMapping(x => x.X);
        dsX.SetYMapping(y => y.Y);
    }


    public ChartPlotter TraceCourbe(EnumerableDataSource<Point> dsX)
    {
        CourbeChartPlotter = new ChartPlotter();
        ViewPortAxesRangeRestriction restr = new ViewPortAxesRangeRestriction
        {
            XRange = new DisplayRange(0, nbPoint + 1),
            YRange = new DisplayRange(-2, 2)
        };
        CourbeChartPlotter.Viewport.Restrictions.Add(restr);
        CourbeChartPlotter.AddLineGraph(dsX, Colors.Red, 2, "X");
        return CourbeChartPlotter;
    }

I want memory not increase each time I redraw the chart or at least when I GC.Collect() after all Measure retrieve a normal memory usage.

MrB3NiT0
  • 137
  • 2
  • 16

1 Answers1

0

I'm assuming you're redrawing the chart by repeatedly calling TraceCourbe method, and reassigning CourbeChartPlotter property, then displaying that. In that case, you probably have a memory leak because something (for example another property, control or an event subscriber) is holding a reference to your ChartPlotter control even after it is reassigned and theoretically removed (your case may be similar to this one).

You can reassign the chart's data source instead, as is described here.

Arie
  • 5,251
  • 2
  • 33
  • 54