chaining of destroy signal

Stephen Evanchik evanchsa at clarkson.edu
Tue Feb 15 18:39:26 EST 2005


On Mon, 2005-02-14 at 17:46 -0500, c.shoemaker at cox.net wrote:

> >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(" ");
> > }

This isn't necessary in the GTK2 .. however what I have been doing is 
overriding the dispose function whenever I encounter a destroy.

I'm not an expert either, but I think destroy is meant to be overridden
by instances of the object whereas dispose is an object implementor
function. 


> 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:
>  g_object_unref(G_OBJECT(gtk_tree_view_get_model(tree_view)))
> 
> in the destroy function?

Not in the destroy function, in dispose which is where objects are
supposed to unref anything that they hold refs to (that's paraphrased
from an email I discovered.. I'll try and locate it.) 

Feel free to correct me if I'm wrong..


Stephen



More information about the gnucash-devel mailing list