首页 文章

内存泄漏使用OxyPlot与Mono / C#

提问于
浏览
1

我正在使用OxyPlot(v1.0.0)用Mono / C#绘制图表 . 它由Mono的运行时环境在嵌入式Linux上运行 .

每次我更新绘图或它更新自己更多的内存声称 . 这是通过我的代码(InvalidatePlot调用)或OxyPlot本身完成的(例如,当我在绘图上滑动并显示跟踪器时) . 即使通过更改窗口大小,也会触发此问题 .
任务管理器显示的程序内存从30 MB开始,在20分钟内爬升到400,应用程序冻结并在以后崩溃 . 此外,控制台上显示以下输出:

(Testsoftware:673): Glib-Critical **: Source ID XXX was not found when attempting to remove it

我不知道这是不是真正的问题 . 我使用Mono分析器获取有关调用和堆组合的一些信息 . 令我惊讶的是,当程序崩溃时,所显示的分配内存仅为9 MB左右,而OxyPlot提供的对象不是主要十分之一 . 当它不影响堆时,它来自哪里?
即使是Valgrind也没有帮助找到问题 . 值得注意的是,虽然任务管理器记录了60 MB的内存增长,但Valgrind的统计数据仅为4 MB . 堆栈跟踪的最大部分无法解决,因为Valgrind没有看过Monos JIT .

要手动更新绘图,需要明确更新其模型 . 这些是我在我的代码中尝试过的东西,但是所有这些都会导致分配的内存增长:

  • Diagram.InvalidatePlot(true); (官方方法)

  • Diagram.Model = myModel;

  • 将Diagram.Model设置为NULL并将其构建为新的

方法调用摘要还显示,大量调用是GLib.Timeout / TimeoutProxy:Handler()调用 . 也许这可能是一个迹象 .

我认为这是OxyPlot的一个问题 . 但我希望有人可以帮助我 - 谢谢!

编辑:重现的代码片段 . 通过在绘图上滑动,跟踪器出现 - 并且内存上升 . 这只是更新图表的一种方法,但所有其他方法也会导致问题 .

using System;
using OxyPlot.GtkSharp;
using OxyPlot.Series;
using OxyPlot.Axes;
using OxyPlot;
using Gtk;

public partial class MainWindow: Gtk.Window
{
    public MainWindow () : base (Gtk.WindowType.Toplevel)
    {
        Build ();
        var model = new PlotModel ();
        var plot = new LineSeries () { Title = "Plot", Color = OxyColors.Red, TrackerFormatString="Tracker" };
        plot.Points.Add (new DataPoint (10, 5)); //Add two points to get a graph
        plot.Points.Add (new DataPoint (5, 10));
        model.Series.Add (plot); //Add plot to the model
        model.Axes.Add (new LinearAxis { Title = "Bottom", Position = AxisPosition.Bottom}); //Add axes to the model
        model.Axes.Add (new LinearAxis { Title = "Left", Position = AxisPosition.Left});
        var diagramm = new PlotView();
        diagramm.Model = model; //Add model to the view
        diagramm.Visible = true;
        alignment1.Add (diagramm); //Alignment1 lies in MainWindow
    }
    protected void OnDeleteEvent (object sender, DeleteEventArgs a)
    {
        Application.Quit ();
        a.RetVal = true;
    }
}

MainWindow GUI由设计器工具创建:

public partial class MainWindow
{
    private global::Gtk.Alignment alignment1;

    protected virtual void Build ()
    {
        global::Stetic.Gui.Initialize (this);
        // Widget MainWindow
        this.Name = "MainWindow";
        this.Title = global::Mono.Unix.Catalog.GetString ("MainWindow");
        this.WindowPosition = ((global::Gtk.WindowPosition)(4));
        // Container child MainWindow.Gtk.Container+ContainerChild
        this.alignment1 = new global::Gtk.Alignment (0.5F, 0.5F, 1F, 1F);
        this.alignment1.Name = "alignment1";
        this.Add (this.alignment1);
        if ((this.Child != null)) {
            this.Child.ShowAll ();
        }
        this.DefaultWidth = 400;
        this.DefaultHeight = 300;
        this.Show ();
        this.DeleteEvent += new global::Gtk.DeleteEventHandler (this.OnDeleteEvent);
    }
}

1 回答

  • 0

    经过大量的调试后我发现我无法解决问题 . 该错误位于OxyPlot内部 .

相关问题