From 6334f60e2edc05380bf338ffad27a5d83b3c0505 Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Tue, 31 May 2005 19:22:58 +0000 Subject: [PATCH] 2005-05-31 Mike Kestner * glib/Object.cs : rework the weakref release mechanism to avoid a couple "resurrection" issues. svn path=/trunk/gtk-sharp/; revision=45267 --- ChangeLog | 5 +++++ glib/Object.cs | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index dc1f99758..c044296ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-05-31 Mike Kestner + + * glib/Object.cs : rework the weakref release mechanism to avoid a + couple "resurrection" issues. + 2005-05-25 Mike Kestner * configure.in.in : remove crosspkgdir arg that causes trouble with diff --git a/glib/Object.cs b/glib/Object.cs index e16c98ff3..f6386de8e 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -34,7 +34,7 @@ namespace GLib { bool disposed = false; Hashtable data; static Hashtable Objects = new Hashtable(); - static Queue PendingDestroys = new Queue (); + static ArrayList PendingDestroys = new ArrayList (); static bool idle_queued; ~Object () @@ -67,6 +67,7 @@ namespace GLib { Console.WriteLine ("Exception while disposing a " + o + " in Gtk#"); throw e; } + Objects.Remove (o._obj); o._obj = IntPtr.Zero; } return false; @@ -78,9 +79,8 @@ namespace GLib { return; disposed = true; - Objects.Remove (_obj); lock (PendingDestroys){ - PendingDestroys.Enqueue (this); + PendingDestroys.Add (this); lock (typeof (Object)){ if (!idle_queued){ Idle.Add (new IdleHandler (PerformQueuedUnrefs)); @@ -101,7 +101,11 @@ namespace GLib { Object obj; WeakReference weak_ref = Objects[o] as WeakReference; + if (weak_ref != null && weak_ref.IsAlive) { + lock (PendingDestroys) + PendingDestroys.Remove (weak_ref.Target); + obj = weak_ref.Target as GLib.Object; if (owned_ref) g_object_unref (obj._obj);