chaining of destroy signal

c.shoemaker at c.shoemaker at
Mon Feb 14 17:46:21 EST 2005

I'm pretty new to gobject and friends, but I feel like I'm picking it
up ok.  There are, however, a few things that baffle me.  Here are a

>From gnc-tree-view-price.c:

> static void
> gnc_tree_view_price_destroy (GtkObject *object)
> {
>   GncTreeViewPrice *view;
>   ENTER("view %p", object);
>   g_return_if_fail (object != NULL);
>   g_return_if_fail (GNC_IS_TREE_VIEW_PRICE (object));
>   view = GNC_TREE_VIEW_PRICE (object);
>   if (GTK_OBJECT_CLASS (parent_class)->destroy)
>     (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
>   LEAVE(" ");
> }

which was set in the "class_init" function:
> static void gnc_tree_view_price_class_init (GncTreeViewPriceClass *klass)

like so:

>        o_class = G_OBJECT_CLASS (klass);
>        object_class = GTK_OBJECT_CLASS (klass);
>        /* GObject signals */
>        o_class->finalize = gnc_tree_view_price_finalize;
>        /* GtkObject signals */
>        object_class->destroy = gnc_tree_view_price_destroy;

In the code above, is it necessary to override the destroy signal and
chain it to the parent class?  I would think that when the type system
passes the GncTreeViewPriceClass to the class_init function,
G_OBJECT_CLASS(klass)->destroy is already set to the parent's destroy
function, right?  If the current object never refs any objects then we
don't need to implement the destroy function at all, right?

However, if this object can and does ref other objects, then we need
to unref them in our own destroy function, before chaining to the
parent's destroy function, right?  So, does this object take any refs?
It goes:

>From gnc_tree_view_price_new():
>  /* Create/get a pointer to the existing model for this set of books. */
>  price_db = gnc_pricedb_get_db(book);
>  model = gnc_tree_model_price_new (book, price_db);
>  /* Set up the view private filter on the common model. */
>  f_model = egg_tree_model_filter_new (model, NULL);
>  gtk_object_sink(GTK_OBJECT(model));
>  s_model = gtk_tree_model_sort_new_with_model (f_model);
>  g_object_unref(G_OBJECT(f_model));
>  gtk_tree_view_set_model (tree_view, s_model);
>  g_object_unref(G_OBJECT(s_model));
>  DEBUG("model ref count is %d",   G_OBJECT(model)->ref_count);
>  DEBUG("f_model ref count is %d", G_OBJECT(f_model)->ref_count);
>  DEBUG("s_model ref count is %d", G_OBJECT(s_model)->ref_count);

Doesn't the gtk_object_sink() call imply that we're becoming
responsible for the remaining ref to model?  If so, does that mean
we'd need do something like:

in the destroy function?


More information about the gnucash-devel mailing list