Re: GObject and floating reference count



Hannes Mayr wrote:
Hello,

I'm a little bit confused about the explanation of the floating reference count.

The documentation says about GObject:
"The initial reference a GObject is created with is flagged as a floating reference. This means that it is not specifically claimed to be "owned" by any code portion." http://developer.gnome.org/doc/API/2.0/gobject/gobject-The-Base-Object-Type.html#floating-ref

And about GtkObject:
"The most interesting difference between GtkObject and GObject is the "floating" reference count. A GObject is created with a reference count of 1, owned by the creator of the GObject. (The owner of a reference is the code section that has the right to call g_object_unref() in order to remove that reference.) A GtkObject is created with a reference count of 1 also, but it isn't owned by anyone;"
http://developer.gnome.org/doc/API/2.0/gtk/GtkObject.html

So, the part of GtkObject says GObject is owned by the creator and the docs about GObject itself says it isn't owned by anyone (until g_object_sink() is called).

Who is wrong here? Or maybe I unterstood something wrong...


This is a whole new can of bugs waiting to spill, the answer to your
question is that both are created floating in GTK+-2.10, before that
GObjects were never floating and floating widgets were the main incentive
to keep GtkObject around.

So the docs need love.

Why I'm asking is because I don't know exactly if the following code needs a g_object_unref of the GtkListStore, which has as parent GObject and not GtkObject.

Code:
  GtkListStore *store;
  store = gtk_list_store_new(N_EDIT_TV_COLUMNS,
    G_TYPE_INT,
    G_TYPE_STRING,
    G_TYPE_STRING,
    G_TYPE_INT
  );

  gtk_tree_view_set_model(GTK_TREE_VIEW(tview), GTK_TREE_MODEL(store));

  // is this needed??
  g_object_unref(G_OBJECT(store));


That is a damned good question, in my opinion it should be absolutely
nescisary to unref it; because my opinion is that only GtkWidgets when
added to GtkContainers should be "sunk", if we dont have a clear rule
like that; how will anyone ever know what to unref ?

/me obstinatly leaves it to someone else to open up gtktreeview.c to find out

Cheers,
                     -Tristan



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