Re: g_object_add_toggle_ref

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

 



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



[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux