Re: Leak with gtk_tree_item.
- From: Havoc Pennington <hp redhat com>
- To: Linus Larsson <linus mediasvar se>
- Cc: gtk-list gnome org
- Subject: Re: Leak with gtk_tree_item.
- Date: 19 Apr 2001 10:27:35 -0400
Linus Larsson <linus mediasvar se> writes:
> I have a strange problem. This leaks like crazy.
>
> item = gtk_tree_item_new();
> gtk_widget_destroy(item);
>
> Anyone know whats up.
>
Destroy doesn't affect the reference count directly q- it just requests
that anyone holding a refcount drop their reference to the
object. Since you never put the tree item in a tree, there is no one
holding its reference count (it only has the "floating" reference
which is unowned).
To get rid of the floating reference, call gtk_object_sink():
item = tree_item_new ();
gtk_object_sink (item);
/* now item is invalid */
Normally when you put the widget in a tree, the tree will call:
gtk_object_ref (item); /* obtain a reference owned by the tree */
gtk_object_sink (item); /* remove unowned floating reference if any */
So at that point the ref count is 1, and owned by the tree; so calling
gtk_object_destroy() causes the tree to unref the item and free it.
While when you are calling destroy, the ref count is 1 but floating
(owned by no one), since the floating ref is unowned, there is no one
to honor the destroy request.
Again, "destroy" simply means "please break references," it does not
guarantee the object is freed; object lifecycle is controlled by the
reference count.
Anyway, short answer, if you put the tree items in a tree then there
is no problem, so don't worry about it. ;-)
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]