2005-08-15 Mike Kestner <mkestner@novell.com>

* 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
This commit is contained in:
Mike Kestner 2005-08-15 15:56:16 +00:00
parent 622c360576
commit b5964c52d0
3 changed files with 19 additions and 17 deletions

View File

@ -1,3 +1,10 @@
2005-08-15 Mike Kestner <mkestner@novell.com>
* 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 <danw@novell.com>
* parser/gapi2xml.pl (addFuncElems): if a struct or boxed type has

View File

@ -3,7 +3,7 @@
// Authors: Mike Kestner <mkestner@speakeasy.net>
//
// 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);
}

View File

@ -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 {