Re: GtkWindow destroy problem
- From: Darin Adler <darin bentspoon com>
- To: Martin Baulig <martin home-of-linux org>
- Cc: Gtk Developers <gtk-devel-list gnome org>
- Subject: Re: GtkWindow destroy problem
- Date: Wed, 05 Sep 2001 08:14:39 -0700
on 9/5/01 7:52 AM, Martin Baulig at martin home-of-linux org wrote:
> the following code crashes:
>
> ====
> window = g_object_new (GTK_TYPE_WINDOW, NULL);
>
> g_object_unref (G_OBJECT (window));
> ====
That's right. That's how GtkWindow objects have always worked. They are
already in the hands of their owner when they return from new, and the
caller doesn't get a ref to them that he can unref.
> However, I still call this a serious bug - a GtkWindow is a GObject and
> thus g_object_unref() on it must not crash.
I think you need to learn a bit more about GTK before making this
pronouncement. This is no different in GTK 2 than it was in GTK 1.
Many GObjects give you a reference that you can unref them when you create
them. But most GtkWidget subclasses instead give you a floating reference so
you can't do an unref, instead you do a sink to get rid of the floating
reference. And GtkWindow objects have already been sinked, because they are
already owned by "top-level" which owns all the windows.
So to get rid of a GtkWindow you do a gtk_object_destroy which makes the
top-level relinquish its ownership of the window, it does the unref and the
object goes away. You can only do an unref if you hold a ref and you don't
get a ref when you call g_object_new for an object of a GtkWidget subclass.
Perhaps some GTK expert will correct me, but this is how I understand it.
-- Darin
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]