Re: [gtk-list] *_unref()



"D. Emilio Grimaldo Tunon" <emilio_tunon@nl.compuware.com> writes:

> Can anybody enlighten me regarding *_unref() ?

There is some documentation about this in docs/refcounting.txt.

I assume you do noe about basic reference counting techniques.  Ref
counting Gtk+ widget is a bit unusual in that they are created with a
refcount of 1 but you don't have to unref that if you don't want to.

So, it's OK to create a widget, stick it into a container and forget
about it.  As soon as the widget gets a parent, the initial reference
count is transferred to the container and it is released when the
looses the reference to the widget.

> when do I have to use that? is it after every gtk_widget_destroy()?
> or just for some widgets?  when?

Call it exactly once for every gtk_widget_ref that you have done.  If
you are not doing any gtk_widget_refs, don't call gtk_widget_unref
either.

[ I think there are now some handy performance hack functions in Gtk+
  that violate this rule, but they state so very clearly. ]

> and then, when is it gtk_widget_unref() and when gtk_object_unref()?

They are completely identical.  gtk_widget_unref just calls
gtk_object_unref, but it can save an explicit cast now and then.  If
you find this fishy, just ignore gtk_widget_unref and always use
gkt_object_unref.

> rather confusing...

Hmm, a bit, yes.  The unusual stuff was done for backeards
compatability and once you get the bit about `floating', it's no too
bad, either.  IMO.

>    		gtk_developer_unref(GTK_HUMAN(Emilio));

Don't do that! :-)

I might add that the other ref/unref functions that are in Gtk+ (like
gtk_style_ref, gdk_window_ref, ...) do not employ the `floating'
twist.  With them, you get `things' that have a refcount of 1 at
creation time.  You have to explicitely unref this creation-time
reference count to destroy these `things'.  No magic here.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]