Bug 37598 - Cairo leaks memory.
Summary: Cairo leaks memory.
Status: RESOLVED FIXED
Alias: None
Product: Gtk#
Classification: Mono
Component: gtk-sharp ()
Version: 2.x
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-01-12 00:05 UTC by konkor
Modified: 2016-01-15 20:55 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description konkor 2016-01-12 00:05:20 UTC
Memory leak in Cairo, here simple example from ZetCode Tutorial:

//here is memory leaking about 10 MiB per second...
using Gtk;
using Cairo;
using System;

class SharpApp : Window {


	private double [,] trs = new double[,] {
		{ 0.0, 0.15, 0.30, 0.5, 0.65, 0.80, 0.9, 1.0 },
		{ 1.0, 0.0,  0.15, 0.30, 0.5, 0.65, 0.8, 0.9 },
		{ 0.9, 1.0,  0.0,  0.15, 0.3, 0.5, 0.65, 0.8 },
		{ 0.8, 0.9,  1.0,  0.0,  0.15, 0.3, 0.5, 0.65},
		{ 0.65, 0.8, 0.9,  1.0,  0.0,  0.15, 0.3, 0.5 },
		{ 0.5, 0.65, 0.8, 0.9, 1.0,  0.0,  0.15, 0.3 },
		{ 0.3, 0.5, 0.65, 0.8, 0.9, 1.0,  0.0,  0.15 },
		{ 0.15, 0.3, 0.5, 0.65, 0.8, 0.9, 1.0,  0.0, }
	};

	private short count = 0;
	private DrawingArea darea;

	public SharpApp() : base("Waiting")
	{
		SetDefaultSize(200, 200);
		SetPosition(WindowPosition.Center);
		DeleteEvent += delegate { Gtk.Application.Quit(); };

		GLib.Timeout.Add(40, new GLib.TimeoutHandler(OnTimer));

		darea = new DrawingArea();
		darea.Drawn += OnDrawn;

		Add(darea);

		ShowAll();
	}

	bool OnTimer() 
	{ 
		count += 1;
		darea.QueueDraw();
		return true;
	}        


	void OnDrawn(object sender, DrawnArgs args)
	{
		//DrawingArea area = (DrawingArea) sender;
		Cairo.Context cr =  Gdk.CairoHelper.Create(darea.Window);

		cr.LineWidth = 3;
		cr.LineCap = LineCap.Round;

		int width, height;
		width = Allocation.Width;
		height = Allocation.Height;

		cr.Translate(width/2, height/2);

		for (int i = 0; i < 8; i++) {
			cr.SetSourceRGBA(0, 0, 0, trs[count%8, i]);
			cr.MoveTo(0.0, -10.0);
			cr.LineTo(0.0, -40.0);
			cr.Rotate(Math.PI/4);
			cr.Stroke();
		}
		cr.GetTarget ().Dispose ();
		cr.Dispose();
	}

	public static void Main()
	{
		Gtk.Application.Init();
		new SharpApp();
		Gtk.Application.Run();
	}
}
Comment 1 konkor 2016-01-12 00:10:33 UTC
PS: I wanted to try Monodevelop in native Linux Environment. And i think MONO is dead project for every platform. We will w8 for MS on Linux...
Comment 2 Miguel de Icaza [MSFT] 2016-01-15 20:55:56 UTC
The included sample did not compile, the one at the end of this message does.

But I could not reproduce the leak on OSX.

using Gtk;
using Cairo;
using System;

class SharpApp : Window {


        private double [,] trs = new double[,] {
                { 0.0, 0.15, 0.30, 0.5, 0.65, 0.80, 0.9, 1.0 },
                { 1.0, 0.0,  0.15, 0.30, 0.5, 0.65, 0.8, 0.9 },
                { 0.9, 1.0,  0.0,  0.15, 0.3, 0.5, 0.65, 0.8 },
                { 0.8, 0.9,  1.0,  0.0,  0.15, 0.3, 0.5, 0.65},
                { 0.65, 0.8, 0.9,  1.0,  0.0,  0.15, 0.3, 0.5 },
                { 0.5, 0.65, 0.8, 0.9, 1.0,  0.0,  0.15, 0.3 },
                { 0.3, 0.5, 0.65, 0.8, 0.9, 1.0,  0.0,  0.15 },
                { 0.15, 0.3, 0.5, 0.65, 0.8, 0.9, 1.0,  0.0, }
        };

        private short count = 0;
        private DrawingArea darea;

        public SharpApp() : base("Waiting")
        {
                SetDefaultSize(200, 200);
                SetPosition(WindowPosition.Center);
                DeleteEvent += delegate { Gtk.Application.Quit(); };

                GLib.Timeout.Add(40, new GLib.TimeoutHandler(OnTimer));

                darea = new DrawingArea();
                darea.ExposeEvent += Draw;

                Add(darea);

                ShowAll();
        }

        bool OnTimer()
        {
                count += 1;
                darea.QueueDraw();
                return true;
        }


        void Draw(object sender, ExposeEventArgs args)
        {
                DrawingArea area = (DrawingArea) sender;
                Cairo.Context cr =  Gdk.CairoHelper.Create(area.GdkWindow);

                cr.LineWidth = 3;
                cr.LineCap = LineCap.Round;

                int width, height;
                width = Allocation.Width;
                height = Allocation.Height;

                cr.Translate(width/2, height/2);

                for (int i = 0; i < 8; i++) {
                        cr.SetSourceRGBA(0, 0, 0, trs[count%8, i]);
                        cr.MoveTo(0.0, -10.0);
                        cr.LineTo(0.0, -40.0);
                        cr.Rotate(Math.PI/4);
                        cr.Stroke();
                }
                cr.GetTarget ().Dispose ();
                cr.Dispose();
        }

        public static void Main()
        {
                Gtk.Application.Init();
                new SharpApp();
                Gtk.Application.Run();
        }
}