À l'étude

Possible memory leak issue

ChrisM il y a 5 ans mis à jour par David Gillard il y a 2 ans 2

I am building a Xamarin.Forms app that needs to plot several graphs that update with new data every second. I've found Oxyplot to be a good library to use, but I've encountered memory issues. To see if the problem was being caused by Oxyplot and not somewhere else in the code, I created a simple Xamarin.Forms app that has a single line series to which a new data point is added every second and ran it through the Xamarin Profiler.

What I find is that the memory usage continues to slowly but steadily grow over time. According to the profiler, there are a number of System.Collections.Generic.Dictionary.Entry<System.IntPtr,System.Collections.Generic.List<System.WeakReference>>[] which continue to grow in size over time. With every call to InvalidatePlot(true), the memory usage increases.

I've included the code here, it's just about the most simple example of what I need the graph to do in my actual application.

namespace SimpleGraph{
    public class MyPage : ContentPage
        PlotModel myPlotModel = new PlotModel ();
        PlotView myPlotView = new PlotView(){
            VerticalOptions = LayoutOptions.Fill,
            HorizontalOptions = LayoutOptions.Fill,
        public MyPage ()
            int ctr = 3;
            myPlotView.Model = myPlotModel;
            Content = myPlotView;
            SetupGraphs ();
            Device.StartTimer (new TimeSpan (0, 0, 0, 1), () => {        
                Random r = new Random ();
                return true;
        public void SetupGraphs()
            Random r = new Random ();
            myPlotModel.Axes.Add (new LinearAxis { Position = AxisPosition.Bottom });
            myPlotModel.Axes.Add (new LinearAxis { Position = AxisPosition.Left, Maximum = 10, Minimum = 0 });

            LineSeries series1 = new LineSeries {
                MarkerType = MarkerType.Circle,
                MarkerSize = 4,
                MarkerStroke = OxyColors.White
            series1.Points.Add (new DataPoint (0.0, r.Next(0, 10)));
            series1.Points.Add (new DataPoint (1.4, r.Next(0, 10)));
            series1.Points.Add (new DataPoint (2.0, r.Next(0, 10)));

            myPlotModel.Series.Add (series1); 

        public void UpdateGraphs(int ctr)
            Random r = new Random ();

            DataPoint dp = new DataPoint(ctr, r.Next (0, 10));
            LineSeries series1 = myPlotModel.Series [0] as LineSeries;
            series1.Points.Add (dp);
            if (series1.Points.Count > 30) {
                series1.Points.RemoveAt (0);

Just to make things more interesting, the issue only occurs when using Android 5 or above.

I am new to mobile development, so I apologize if I've done something stupid, or am just using OxyPlot incorrectly.

I am using version 1.0.0-unstable1957 of Oxyplot.

Any assistance would be greatly appreciated.

À l'étude

This sounds like a bug, can you create a github issue?

Sorry, I don't know what is going on...

I've experienced what I believe is essentially the same problem with OxyPlot for GTK 1.0.0 using monodevelop.