From cf139575c229eebd9e49fa1cf73025f2ac038890 Mon Sep 17 00:00:00 2001 From: Ettore Perazzoli Date: Sat, 26 Oct 2002 08:37:48 +0000 Subject: [PATCH] Changed so that Objects is a hash of WeakReferences instead of hashing the real objects. Without this change, GObjects were never collected. (Raw, set): Put a WeakReference to the object in Objects. (Object.GetObject): Get the WeakReference from Objects, and from there the actual object. (Object.DisposeNative): Remove the Raw pointer from Objects. svn path=/trunk/gtk-sharp/; revision=8578 --- ChangeLog | 10 ++++++++++ glib/Object.cs | 12 ++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8dd1c35a3..78d293399 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2002-10-26 Ettore Perazzoli + + * glib/Object.cs: Changed so that Objects is a hash of + WeakReferences instead of hashing the real objects. Without this + change, GObjects were never collected. + (Raw, set): Put a WeakReference to the object in Objects. + (Object.GetObject): Get the WeakReference from Objects, and from + there the actual object. + (Object.DisposeNative): Remove the Raw pointer from Objects. + 2002-10-26 Mike Kestner * api/*.xml : get libgda and libgnomedb metadata setup diff --git a/glib/Object.cs b/glib/Object.cs index e40cb2038..85a821388 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -61,6 +61,8 @@ namespace GLib { if (_obj == IntPtr.Zero) return; + Objects.Remove (Raw); + GC.SuppressFinalize (this); g_object_unref (_obj); _obj = IntPtr.Zero; @@ -104,8 +106,9 @@ namespace GLib { public static Object GetObject(IntPtr o) { - Object obj = (Object)Objects[o]; - if (obj != null) return obj; + WeakReference obj = Objects[o] as WeakReference; + if (obj != null) + return obj.Target as GLib.Object; return GtkSharp.ObjectManager.CreateObject(o); } @@ -117,7 +120,8 @@ namespace GLib { /// Dummy constructor needed for derived classes. /// - public Object () {} + public Object () { + } /// /// Object Constructor @@ -148,7 +152,7 @@ namespace GLib { return _obj; } set { - Objects [value] = this; + Objects [value] = new WeakReference (this); _obj = value; } }