Reputation: 9223
There are two functions in GLib that work with the reference counting of the GObject objects:
g_object_ref
increases reference count of the object, doesn't handle floating references.g_object_ref_sink
increases reference count of the object or just removes floating flag from the object if the reference is floating.Since we don't know if the object is floating or not, we should always use g_object_ref_sink
, shouldn't we? If I am wrong, when should we use g_object_ref
and when should we use g_object_ref_sink
? Should we use g_object_ref_sink
only for GInitiallyUnowned
objects?
Upvotes: 1
Views: 757
Reputation: 5768
You should generally know the type of an object you’re handling (i.e. pointers typically have more specific types than GObject*
), so you’ll know if it’s potentially floating or not. GObject-based APIs which use floating references are documented as using them. Anything which isn’t documented as using floating references, doesn’t.
Upvotes: 1