Closed hying-caritas closed 10 years ago
if the object ownership is transferred, the reference count should have been increased for caller already. So to setup GC for an object, it should be enough only to call g-object-ref-sink if it is floating to get the ownership.
ptr = gtk_label_new() -- `the object ownership is transferred', so g_object_ref_sink(ptr); then gtk_add_window(window, ptr); -- ptr not floated, so window doesn't claim it. then drop ptr (out of scope). Oops: we cannot call unref, because then ptr will be destroyed in window. and we cannot forget it, because, when window will be destroyed, ptr will be live forever.
So, no g-object-ref-sink for user functions. Either g-object-ref and g-object-unref in GC, or nothing at all.
On Tue, Apr 22, 2014 at 12:09 AM, Kalimehtar notifications@github.comwrote:
if the object ownership is transferred, the reference count should have been increased for caller already. So to setup GC for an object, it should be enough only to call g-object-ref-sink if it is floating to get the ownership.
ptr = gtk_label_new() -- `the object ownership is transferred', so g_object_ref_sink(ptr);
Now reference count of ptr is 1, not floating.
then gtk_add_window(window, ptr); -- ptr not floated, so window doesn't claim it.
During gtk_add_window, g_object_ref_sink(ptr) will be called, so reference count of ptr becomes 2 because it is not floating.
then drop ptr (out of scope).
unref, now reference count of ptr becomes 1
Oops: we cannot call unref, because then ptr will be destroyed in window. and we cannot forget it, because, when window will be destroyed, ptr will be live forever.
When window is destroyed, reference count of ptr becomes 0 and will be reclaimed.
So, no g-object-ref-sink for user functions. Either g-object-ref and g-object-unref in GC, or nothing at all.
Yes. It should work.
Now, GC processing is done in free. That is not appropriate, because
a) Some input argument need to be freed, but not GC-ed b) GC need to access values instead of memory location
So added individual GC function in converter/translator/arg-processor and call them after function call.
For object GC processing, when caller get an object from return value or out argument of a function, if the object ownership is transferred, the reference count should have been increased for caller already. So to setup GC for an object, it should be enough only to call g-object-ref-sink if it is floating to get the ownership.