diff --git a/ChangeLog b/ChangeLog index 103a87ef9..24fe2bdb4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-02-02 Mike Kestner + + * glib/Value.cs : add dispose queue and idle handler so we can + unset GValues that are created by the binding ctors. + [Fixes #53490] + 2004-02-02 Todd berman * gdk/Event*.custom: added fix for bug #53729. diff --git a/glib/Value.cs b/glib/Value.cs index ae5a42b7d..21095e5fb 100755 --- a/glib/Value.cs +++ b/glib/Value.cs @@ -7,6 +7,7 @@ namespace GLib { using System; + using System.Collections; using System.Runtime.InteropServices; using GLibSharp; @@ -31,11 +32,39 @@ namespace GLib { [DllImport("libglib-2.0-0.dll")] static extern void g_free (IntPtr mem); + [DllImport("libgobject-2.0-0.dll")] + static extern void g_value_unset (IntPtr mem); + ~Value () { Dispose (); } + static bool idle_queued; + static Queue idle_queue = new Queue (); + + static bool DoDispose () + { + IntPtr [] vals; + + lock (idle_queue){ + vals = new IntPtr [idle_queue.Count]; + idle_queue.CopyTo (vals, 0); + idle_queue.Clear (); + } + lock (typeof (Value)) + idle_queued = false; + + foreach (IntPtr v in vals) { + if (v == IntPtr.Zero) + continue; + + g_value_unset (v); + g_free (v); + } + return false; + } + public void Dispose () { if (_val != IntPtr.Zero) { IntPtr rawtype = gtksharp_value_get_value_type (_val); @@ -44,7 +73,15 @@ namespace GLib { } if (needs_dispose) - g_free (_val); + lock (idle_queue) { + idle_queue.Enqueue (_val); + lock (typeof (Value)){ + if (!idle_queued){ + Idle.Add (new IdleHandler (DoDispose)); + idle_queued = true; + } + } + } _val = IntPtr.Zero; } @@ -54,7 +91,6 @@ namespace GLib { } } - // import the glue function to allocate values on heap [DllImport("gtksharpglue")]