Currently I am using g_object_add_toggle_ref() and
g_object_set_qdata(). The first for the garbage collection tasks, and
the later for retrieving the proxy object from the associated GTK
GObject, for example when functions like gtk_widget_get_parent() are
used. That seems to work, but I have the feeling of some redundancy.
Both gobject functions are passed the address of my proxy object. But
g_object_add_toggle_ref() seems to offer no support to get the address
back, that is why I use additional g_object_set_qdata() which allows me
to get back the proxy address with g_object_get_qdata().
So after a call of g_object_add_toggle_ref() ref_count of an object is
always greater or equal to two? But how can now that value drop ever
again below 2? When a new references is added, it increases, and when
that references is removed, the value is decreased. But never below 2
this way? It is a bit confusing indeed.
More confusing is, that g_object_ref_sink () seems to exist since
gobject release 2.10, while g_object_add_toggle_ref () seems to exists
already since 2.8.
And, for my understanding of English wording, the documentation of
g_object_ref_sink() contradicts even itself:
"Increase the reference count of object
, and possibly remove the
floating reference, if object
has a floating reference.
In other words, if the object is floating, then this call "assumes
ownership" of the floating reference, converting it to a normal
reference by clearing the floating flag while leaving the reference
count unchanged. If the object is not floating, then this call
adds a new normal reference increasing the reference count by one."
I assume, that the second part is correct. Maybe the first sentence
should be something like "Increase the reference count of object
, OR possibly"
So it will be not that easy to get fully working Garbage Collector