Package: glib

Function g-variant-ref-sink

Lambda List

g-variant-ref-sink (value)

Arguments

value -- a g-variant instance

Return Value

The same value.

Details

The g-variant structure uses a floating reference count system. All functions with names starting with g_variant_new_ return floating references.

Calling the function g-variant-ref-sink on a g-variant instance with a floating reference will convert the floating reference into a full reference. Calling the function g-variant-ref-sink on a non-floating g-variant instance results in an additional normal reference being added.

In other words, if value is floating, then this call "assumes ownership" of the floating reference, converting it to a normal reference. If value is not floating, then this call adds a new normal reference increasing the reference count by one.

All calls that result in a g-variant instance being inserted into a container will call the function g-variant-ref-sink on the instance. This means that if the value was just created (and has only its floating reference) then the container will assume sole ownership of the value at that point and the caller will not need to unreference it. This makes certain common styles of programming much easier while still maintaining normal refcounting semantics in situations where values are not floating.
 

See also

2020-11-30