Re: Widget ref-count on creation
- From: Tristan Van Berkom <vantr touchtunes com>
- To: Russell Shaw <rjshaw netspace net au>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Widget ref-count on creation
- Date: Tue, 22 Jun 2004 13:51:17 -0400
Russell Shaw wrote:
so i assume this increases the refcount to 2 (couldn't tell
by looking at gtk source). So, if the containing window is
destroyed, it will release its refcount. However, the ttt
widget will still have a refcount of 1 and hang around.
What is the correct way of handling the refcount on widget
creation?
I believe that at some point in time (gtk+-1.2 ==> gtk+-2.0 I think)
that this behaviour was changed, in the prior; the correct process was to:
// create widget
my_widget = g_object_new(MY_OBJECT_TYPE, NULL); // <-- refcount 1
// add to a container
gtk_container_add(container, my_widget); // <-- refcount 2
// pass ownership to the container
g_object_unref(my_widget); // <-- refcount 1
But since then (because that code seemed redundant or encumbersome),
GtkObject and its subclasses are created with what is called a floating
reference, which in turn is unreferenced by the container implementation
by calling gtk_object_sink(); (after the container takes ownership of
the GtkObject by calling g_object_ref(); )
So any GtkObject at creation time has no "owner".
Cheers,
-Tristan
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]