2008-04-17 Mike Kestner <mkestner@novell.com>

* glib/ToggleRef.cs: Add a Harden method to switch to a standard
	ref and just leak it.
	* gtk/Application.cs: revert the QuitPrepare stuff since it didn't
	always work.

svn path=/trunk/gtk-sharp/; revision=101021
This commit is contained in:
Mike Kestner 2008-04-17 16:17:37 +00:00
parent cff6726824
commit d2a74c9a37
3 changed files with 31 additions and 5 deletions

View file

@ -1,3 +1,10 @@
2008-04-17 Mike Kestner <mkestner@novell.com>
* glib/ToggleRef.cs: Add a Harden method to switch to a standard
ref and just leak it.
* gtk/Application.cs: revert the QuitPrepare stuff since it didn't
always work.
2008-04-17 Mike Kestner <mkestner@novell.com>
* gtk/TreeModelAdapter.custom:

View file

@ -27,6 +27,7 @@ namespace GLib {
internal class ToggleRef {
bool hardened;
IntPtr handle;
object reference;
GCHandle gch;
@ -81,11 +82,30 @@ namespace GLib {
foreach (Signal s in Signals.Values)
s.Free ();
Signals.Clear ();
g_object_remove_toggle_ref (handle, ToggleNotifyCallback, (IntPtr) gch);
if (hardened)
g_object_unref (handle);
else
g_object_remove_toggle_ref (handle, ToggleNotifyCallback, (IntPtr) gch);
reference = null;
gch.Free ();
}
internal void Harden ()
{
// Added for the benefit of GnomeProgram. It releases a final ref in
// an atexit handler which causes toggle ref notifications to occur after
// our delegates are gone, so we need a mechanism to override the
// notifications. This method effectively leaks all objects which invoke it,
// but since it is only used by Gnome.Program, which is a singleton object
// with program duration persistence, who cares.
g_object_ref (handle);
g_object_remove_toggle_ref (handle, ToggleNotifyCallback, (IntPtr) gch);
if (reference is WeakReference)
reference = (reference as WeakReference).Target;
hardened = true;
}
void Toggle (bool is_last_ref)
{
if (is_last_ref && reference is GLib.Object)
@ -126,6 +146,9 @@ namespace GLib {
[DllImport("libgobject-2.0-0.dll")]
static extern void g_object_remove_toggle_ref (IntPtr raw, ToggleNotifyHandler notify_cb, IntPtr data);
[DllImport("libgobject-2.0-0.dll")]
static extern IntPtr g_object_ref (IntPtr raw);
[DllImport("libgobject-2.0-0.dll")]
static extern void g_object_unref (IntPtr raw);

View file

@ -131,15 +131,11 @@ namespace Gtk {
return gtk_main_iteration_do (blocking);
}
public static event EventHandler QuitPrepare;
[DllImport("libgtk-win32-2.0-0.dll")]
static extern void gtk_main_quit ();
public static void Quit ()
{
if (QuitPrepare != null)
QuitPrepare (null, EventArgs.Empty);
gtk_main_quit ();
}