chaining of destroy signal

Chris Shoemaker c.shoemaker at cox.net
Tue Feb 15 19:34:44 EST 2005


On Tue, Feb 15, 2005 at 06:57:22PM -0500, David Hampton wrote:
> > 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?
> 
> When the model is created it is created with an initial reference.  Once
> the gnc_tree_model_price has been added to the egg_tree_model_filter
> (which adds its own reference) this initial reference can and should be
> dropped so that the gnc_tree_model_price will be destroyed when the
> egg_tree_model_filter is destroyed.  I believe this could be changed to
> a g_object_unref, but I'm not sure.  I know I counted references on this
> at runtime and everything was correct.  It is definitely wrong though to
> be calling a gtk_object_xxx function on something that is only based on
> a g_object.  Lots of gtk_objects in gnucash-1.x were converted to
> g_objects for 2.x, and bugs like this have slipped in.

Ok, I didn't realize that egg_tree_model_filter ref'd the model.  (Are
there html API docs for egg stuff?)  But, I think the model is still
based on gtkObject so no bug here... yet. :)

-chris


More information about the gnucash-devel mailing list