Hi Stefan; I very much doubt anybody here has knowledge of toggle reference and language bindings. You want gtk-devel-list@xxxxxxxxx, or you want to join the #gtk+ IRC channel on irc.gnome.org. As a note, though: > But when the user creates widgets and never add them to a container, there state > remains ref count 2 floating All GC language bindings will immediately sink the floating reference, as it makes memory management harder for them (it's a C feature, after all). So my suggestion is to immediately and automatically sink the floating reference inside your wrapper around g_object_new() before it returns the instance to the non-C side. Ciao, Emmanuele. On 25 June 2017 at 10:38, Stefan Salewski <mail@xxxxxxxxxxxx> wrote: > On Tue, 2017-06-06 at 14:33 +0200, Stefan Salewski wrote: >> so after call of g_object_add_toggle_ref() ref_count is indeed 2, and >> after call of g_object_unref() the toggleNotify() callback is >> activated. > > Some more investigations seems to indicate: > > When I create a widget and apply g_object_add_toggle_ref(), then ref > count is increased to 2 and the widget is still floating, When I now > add that widget to a container, object is sunk, ref count stays at 2, > and the toggle ref callback in not yet called. But when I remove the > widget from the container again, ref count decreases to 1, and the > toggle ref callback is called. This is fine, as the callback can now > decrease refcount of the proxy object as well. Adding that widget to > the container again works also, callback is called... > > But there is one drawback: In GC languages the user is generally free > to create a large number of object and just forget about them. But when > the user creates widgets and never add them to a container, there state > remains ref count 2 floating, and they are keep alive until program > terminates. > > Well, we may say that the user should not do that, because it makes no > sense. > > A possible fix would be to fake a conainer add/remove operation. I can > do that by a ref_sink/unref function call on the widget after call of > g_object_add_toggle_ref(). That results in a ref count of 1 and a not > floating object, which behaves fine futher. But I am not sure if I > should do that fake, maybe it again generates other problems. > > > _______________________________________________ > gtk-list mailing list > gtk-list@xxxxxxxxx > https://mail.gnome.org/mailman/listinfo/gtk-list -- https://www.bassi.io [@] ebassi [@gmail.com] _______________________________________________ gtk-list mailing list gtk-list@xxxxxxxxx https://mail.gnome.org/mailman/listinfo/gtk-list