Re: gtk_object_unref
- From: Havoc Pennington <hp redhat com>
- To: "Jean-Christophe Berthon" <jean-christophe berthon cgey com>
- Cc: "Gtk List" <gtk-list gnome org>
- Subject: Re: gtk_object_unref
- Date: 02 Oct 2001 01:29:03 -0400
"Jean-Christophe Berthon" <jean-christophe berthon cgey com> writes:
> (I've read some older threads about it - like the one about the container -
> but in my case my objects and points are drawings on a gtk-canvas and I want
> to ref and unref some of the GtkCanvasItem that are shared...)
>
>
> I hope I've been clear enough, if you need more explanation, tell me what
> you didn't understand and I will try to say it differently.
Say you create the canvas item to give it to object A - do you also
reference it?
If not, then you are assuming ownership of the "floating" reference,
which isn't allowed. The canvas will then strip the floating reference
off the item when you add the item to the canvas; and object A will
end up not owning any reference at all.
If you do this:
obj = whatever_gtk_object_new ();
Then the immediate situation is that "obj" has one floating reference,
and zero owned references. To remove the floating reference, do this:
gtk_object_sink (obj);
That will finalize the object if it hasn't already been finalized.
What the canvas does is this:
gtk_object_ref (obj);
gtk_object_sink (obj);
So then "obj" has one reference owned by the canvas, and zero floating
references.
Anyhow, short answer, you need another gtk_object_ref(), rather than
taking ownership of the floating reference. No one can ever own the
floating reference; if you want to call unref on a GtkObject, you must
first call ref; there are no exceptions, even if you created the
object yourself.
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]