Method

GLibVariantref_sink

since: 2.24

Declaration [src]

GVariant*
g_variant_ref_sink (
  GVariant* value
)

Description [src]

GVariant uses a floating reference count system. All functions with names starting with g_variant_new_ return floating references.

Calling g_variant_ref_sink() on a GVariant with a floating reference will convert the floating reference into a full reference. Calling g_variant_ref_sink() on a non-floating GVariant results in an additional normal reference being added.

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

All calls that result in a GVariant instance being inserted into a container will call 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.

Available since: 2.24

Return value

Type: GVariant

The same value.

The caller of the method takes ownership of the returned data, and is responsible for freeing it.