Re: GObject and Gtk+ Finalization

George <jirka 5z com> writes: 
> /* second version */
> object_new
> /* floating: true, refcount: 1 */
>   /* in pass_object_to_owner */
>   _ref
>   /* floating: true, refcount: 2 */
> /* back */
> _unref
> /* floating: true, refcount: 1 */

You just removed the count owned by pass_object_to_owner(). The
floating count remains, but can be removed at any time.

> In both cases, after this we end up with a refcount of 1, which is
> held by the pass_object_to_owner thing.  If you just ignore the
> floating flag, things should just work.

George, you are on crack. ;-) Yes this "works." No it does not really
work. You can't go removing other people's counts, and claim it's
remotely a good idea because it happens to work out.

What happens if someone else calls sink()? You have no way to be sure
they won't.

I doubt any code has been using GtkObject this way anyway, and you
can't know that it was. User code that called sink() was legitimate
code, because GtkObject exports the sink() interface. Can you show me
any released GtkObject interface that was even documented to work like
> As far as I'm reading the code, the "floating reference" only means that
> the object has a reference count of 1 and the FLOATING flag set.  unref
> itself ignores the FLOATING flag.  I may be missing something.

Yes, you are missing that using this interface has rules of sanity,
and that if you have some GtkObject with different refcount rules than
some other GtkObject you are smoking a lot of crack because GtkObject
is where the refcount interface lives. Changing refcount rules at
random is a good way to create memory leaks/corruption.

I don't know if GtkObject does a g_return_if_fail() if refcount == 0
and floating == TRUE, but it should do so and legitimately could do

Inti adds a floating state to GObject and has this warning in the

Inti::Object::unref ()
  if (floating () && 
      object_->ref_count == 1)
      g_warning ("Calling unref() on an object that has only a
floating reference count. This means that you did not own a reference
to the object; to obtain a reference, you must call ref(). No one owns
the floating reference count. Perhaps you meant to call sink().");
  g_object_unref (object_);


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