Re: Doubt about free or dont free



Hi again,
Gus Koppel wrote:

While the case of returned "const gchar *"s is rather simple, the real
problem to me is that the API docs are quite less explicit when it comes
to more complex objects than just string constants.

For instance, whether and how reference counts of objects related to
treeviews are changed by what GTK+ functions dealing with them remains
undocumented.

For instance: whether gtk_tree_view_set_model() changes the reference
counts of either the newly set or the replaced GtkTreeModel remains as
unclear as whether gtk_tree_view_get_selection() increases the reference
count of the selection object or not.

If I remember right the first function changes reference counts while
the 2nd one doesn't but I may be wrong on this. Frequent explicit checks
on object reference counts after many GTK+ functions are my only way to
make sure about this while developping.

I wish the API docs would be added a line for _every_ get- or set-
function, which explicitly notes whether and how reference counts of
associated objects are changed by that function.


IMHO especially the Gtk docs lack a lot here. For many methods one has
to look into the sources to find out wheter to unref or free. Problem is
that that docs don't use G_CONST_RETURN. Some examples:
gtk_*_get_model()
gtk_combo_box_get_popup_accessible()
gtk_widget_get_accessible()   (this one is 100% undocumented)

Filed as http://bugzilla.gnome.org/show_bug.cgi?id=311536
Please add others you find.
The bug was immediately closed again. The reason given was that returning a const would require one to write stuuf like:
store=g_object_ref(G_OBJECT(gtk_*_get_model(...)));

Where I wouldn mind the cast, this imho reveals that gtk is a bit sloppy with handly references. This way I can keep the returned pointer and it can be destroyed without that one would notice. So maybe the docs should just be more explicit about this.

Stefan



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