【发布时间】:2021-05-22 05:54:49
【问题描述】:
GLib 中有两个函数用于 GObject 对象的引用计数:
-
g_object_ref增加对象的引用计数,不处理浮动引用。 -
g_object_ref_sink增加对象的引用计数,或者如果引用是浮动的,则从对象中删除 floating 标志。
既然我们不知道对象是否浮动,我们应该总是使用g_object_ref_sink,不是吗?如果我错了,我们什么时候应该使用g_object_ref,什么时候应该使用g_object_ref_sink?我们应该只对GInitiallyUnowned 对象使用g_object_ref_sink 吗?
【问题讨论】: