Bug 605247

Summary: GLib.Timeout leaks memory
Product: [Mono] gtk# Reporter: Mike Krueger <mkrueger>
Component: gtk-sharpAssignee: Gtk# Bugs List <gtk-sharp-bugs>
Status: RESOLVED DUPLICATE QA Contact: Gtk# Bugs List <gtk-sharp-bugs>
Severity: Major    
Priority: P5 - None    
Version: 2.x   
Target Milestone: ---   
Hardware: Other   
OS: openSUSE 11.2   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Mike Krueger 2010-05-12 16:54:56 UTC
This program leaks memory:

class Test 
{
        static bool Timeout()
        {
                Console.WriteLine ("TIMEOUT ");
                return false;
        }
        static GLib.TimeoutHandler handler = Timeout;
        public static void Main (string[] args)
        {
                Gtk.Application.Init ();
                do {
                        uint timer = GLib.Timeout.Add (650, handler);
                        GLib.Source.Remove (timer);
                        System.GC.Collect ();
                } while (true);
        }      
}

This one doesn't:


class Test 
{
        static bool Timeout()
        {
                Console.WriteLine ("TIMEOUT ");
                return false;
        }
        static GLib.TimeoutHandler handler = Timeout;
	public static void Main (string[] args)
	{
		Gtk.Application.Init ();
		do {
			uint timer = GlibTimer.Add (650, handler);
			GlibTimer.Remove (timer);
			System.GC.Collect ();
		} while (true);
	}
	class GlibTimer
	{
		public delegate bool TimeoutHandler ();

		public static uint Add (uint timeOut, TimeoutHandler handler)
		{
			return g_timeout_add (timeOut, handler, IntPtr.Zero);
		}
		
		public static void Remove (uint id)
		{
			g_source_remove (id);
		}
		
		[DllImport("libglib-2.0.so")]
		static extern void g_source_remove (uint id);
		
		[DllImport("libglib-2.0.so")]
		static extern uint g_timeout_add (uint id, TimeoutHandler function, IntPtr data);
	}
}
Comment 1 Alan McGovern 2010-05-12 22:17:40 UTC
The first testcase leaks under 2.6.4 and also mono r156824. The second testcase leaks under neither. Possibly related to bug #605295
Comment 2 Mike Krueger 2010-05-17 08:04:20 UTC
Yes it's the same.

*** This bug has been marked as a duplicate of bug 605295 ***