Re: GTK 1.2 - gtk_object_unref() trouble



Darin Adler <darin eazel com> writes:

> on 9/27/00 7:07 AM, Martin Baulig at martin home-of-linux org wrote:
> 
> > Isn't gtk_object_destroy() supposed to set the refcount to
> > zero thus making `object->ref_count > 0' always fail if the
> > object got correctly destroyed or do I miss something ?
> 
> You are missing something. Calling gtk_object_destroy has no effect on the
> ref. count. A destroyed object can have any ref. count and is not finalized
> until the last ref goes away.

Oh. Thanks for the explanation.

> > Btw. I found this while I was wondering why
> > 
> >     plug = bonobo_plug_new (<whatever>);
> > 
> >     gtk_widget_destroy (plug);
> > 
> > works without problems but
> > 
> >     plug = bonobo_plug_new (<whatever>);
> > 
> >     gtk_object_unref (plug);
> > 
> > yields
> > 
> >     Gtk-CRITICAL **: file gtkobject.c: line 1179 (gtk_object_unref):
> >     assertion `object->ref_count > 0' failed.
> 
> That's because top level containers like GtkWindow and GtkWindow subclasses
> are owned by the top level container list. They unref themselves when they
> are destroyed. So you can't unref a BonoboPlug unless you ref it first,
> because you aren't holding a ref (the ref is held by the "top level
> container list"). But you can destroy a BonoboPlug and if there are no other
> references the top level container list will then unref it so it will be
> finalized as well as destroyed.
> 
> It's normally not sufficient to do gtk_object_destroy to get rid of an
> object, because it has no effect on the ref. count -- gtk_object_destroy is
> often a sign of a storage leak if no other code does an unref. But the
> GtkWindow family is an exception to this rule. The correct way to get rid of
> a GtkWindow or subclass is gtk_object_destroy.

So the correct thing to do is to change this gtk_object_unref () to
gtk_object_destroy () ?

-- 
Martin Baulig
martin gnome org (private)
baulig suse de (work)




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