From b5964c52d020c929d27e051686ed652587d8f9ff Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Mon, 15 Aug 2005 15:56:16 +0000 Subject: [PATCH] 2005-08-15 Mike Kestner * glib/Object.cs : hold strong refs for managed subclasses and weakrefs for wrappers. * gtk/Object.custom : don't hold managed refs here, they are now held in GLib.Object. svn path=/trunk/gtk-sharp/; revision=48389 --- ChangeLog | 7 +++++++ glib/Object.cs | 17 +++++++++++------ gtk/Object.custom | 12 +----------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 720d06a75..6ee264f0f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-08-15 Mike Kestner + + * glib/Object.cs : hold strong refs for managed subclasses and + weakrefs for wrappers. + * gtk/Object.custom : don't hold managed refs here, they are now held + in GLib.Object. + 2005-08-11 Dan Winship * parser/gapi2xml.pl (addFuncElems): if a struct or boxed type has diff --git a/glib/Object.cs b/glib/Object.cs index f6386de8e..145ea9d1a 100644 --- a/glib/Object.cs +++ b/glib/Object.cs @@ -3,7 +3,7 @@ // Authors: Mike Kestner // // Copyright (c) 2001-2003 Mike Kestner -// Copyright (c) 2004 Novell, Inc. +// Copyright (c) 2004-2005 Novell, Inc. // // This program is free software; you can redistribute it and/or // modify it under the terms of version 2 of the Lesser GNU General @@ -99,14 +99,18 @@ namespace GLib { if (o == IntPtr.Zero) return null; - Object obj; + Object obj = null; WeakReference weak_ref = Objects[o] as WeakReference; - if (weak_ref != null && weak_ref.IsAlive) { - lock (PendingDestroys) - PendingDestroys.Remove (weak_ref.Target); + if (weak_ref != null && weak_ref.IsAlive) + obj = weak_ref.Target as Object; - obj = weak_ref.Target as GLib.Object; + if (obj == null) + obj = Objects[o] as Object; + + if (obj != null && obj._obj == o) { + lock (PendingDestroys) + PendingDestroys.Remove (obj); if (owned_ref) g_object_unref (obj._obj); return obj; @@ -215,6 +219,7 @@ namespace GLib { for (int i = 0; i < names.Length; i++) native_names [i] = GLib.Marshaller.StringToPtrGStrdup (names [i]); Raw = gtksharp_object_newv (LookupGType ().Val, names.Length, native_names, vals); + Objects [_obj] = this; foreach (IntPtr p in native_names) GLib.Marshaller.Free (p); } diff --git a/gtk/Object.custom b/gtk/Object.custom index 2a50fd505..d339726f8 100755 --- a/gtk/Object.custom +++ b/gtk/Object.custom @@ -30,21 +30,11 @@ [DllImport("libgobject-2.0-0.dll")] private static extern void g_object_ref (IntPtr raw); - static Hashtable managed_subclasses; - static Hashtable ManagedSubclasses { - get { - if (managed_subclasses == null) - managed_subclasses = new Hashtable (); - return managed_subclasses; - } - } - static void NativeDestroy (object o, EventArgs args) { Gtk.Object obj = o as Gtk.Object; if (obj == null) return; - ManagedSubclasses.Remove (obj); obj.Destroyed -= NativeDestroyHandler; obj.Dispose (); } @@ -61,13 +51,13 @@ protected override void CreateNativeObject (string[] names, GLib.Value[] vals) { base.CreateNativeObject (names, vals); - ManagedSubclasses [this] = this; Destroyed += NativeDestroyHandler; } public override void Dispose () { base.Dispose (); + Destroyed -= NativeDestroyHandler; } protected override IntPtr Raw {