Functions like gtk_tree_view_get_selection()

I have no problems with functions with transfer mode “full” like gtk_button_new() for which I use toggle references.

Functions like gtk_widget_get_toplevel(), gdk_display_get_default(), gtk_widget_get_window() with transfer “none” seems to be free of problems also, as the return value never becomes invalid.

But functions like gtk_tree_view_get_selection() with transfer “none” seems to be not that simple, as the returned value can become invalid, for example when TreeView is destroyed.

So I assume that the best solution is calling g_object_ref() on the GtkTreeSelection and let the GC call g_object_unref() when the proxy object goes out of scope.

Will calling g_object_ref() on a GtkTreeSelection effect the TreeView itself also, so that the ref count of the TreeView also increases to keep it alive?

1 Like

I mean the value returned by gtk_widget_get_toplevel can be invalid if you keep it around, the widget might be moved to a different toplevel and the orignal destroyed

Yes, if you want to keep a reference to an object you should take a reference on it

Though things like GtkWindow are a bit interesting

No, it just means that when the GtkTreeView dies and drops it’s reference on the GtkTreeSelection the GtkTreeSelection won’t die since you’ve still got a reference to it. Of course the GtkTreeSelection is probably in a weird state now.

Thanks for your remarks. It is basically what I assumed, the point with gtk_widget_get_toplevel() is a good point. It is indeed not easy to make foolproof GTK language bindings, but I will try to make them as foolproof as possible at least.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.