WeakRef

GObject is the fundamental type providing the common attributes and methods for all object types in GTK+, Pango and other libraries based on GObject. The GObject class provides methods for object construction and destruction, property access methods, and signal support. Signals are described in detail in Signals(3).

GInitiallyUnowned is derived from GObject. The only difference between the two is that the initial reference of a GInitiallyUnowned is flagged as a floating reference. This means that it is not specifically claimed to be "owned" by any code portion. The main motivation for providing floating references is C convenience. In particular, it allows code to be written as:

If container_add_child() will g_object_ref_sink() the passed in child, no reference of the newly created child is leaked. Without floating references, container_add_child() can only g_object_ref() the new child, so to implement this code without reference leaks, it would have to be written as:

The floating reference can be converted into an ordinary reference by calling g_object_ref_sink(). For already sunken objects (objects that don't have a floating reference anymore), g_object_ref_sink() is equivalent to g_object_ref() and returns a new reference. Since floating references are useful almost exclusively for C convenience, language bindings that provide automated reference and memory ownership maintenance (such as smart pointers or garbage collection) should not expose floating references in their API.

Some object implementations may need to save an objects floating state across certain code portions (an example is GtkMenu), to achieve this, the following sequence can be used:

Constructors

this
this(GWeakRef* gWeakRef)

Sets our main struct and passes it to the parent class

this
this(void* object)

Members

Functions

clear
void clear()

Frees resources associated with a non-statically-allocated GWeakRef. After this call, the GWeakRef is left in an undefined state. You should only call this on a GWeakRef that previously had g_weak_ref_init() called on it. Since 2.32

get
void* get()

If weak_ref is not empty, atomically acquire a strong reference to the object it points to, and return that reference. This function is needed because of the potential race between taking the pointer value and g_object_ref() on it, if the object was losing its last reference at the same time in a different thread. The caller should release the resulting reference in the usual way, by using g_object_unref(). Since 2.32

getStruct
void* getStruct()

the main Gtk struct as a void*

getWeakRefStruct
GWeakRef* getWeakRefStruct()
Undocumented in source. Be warned that the author may not have intended to support it.
init
void init(void* object)

Initialise a non-statically-allocated GWeakRef. This function also calls g_weak_ref_set() with object on the freshly-initialised weak reference. This function should always be matched with a call to g_weak_ref_clear(). It is not necessary to use this function for a GWeakRef in static storage because it will already be properly initialised. Just use g_weak_ref_set() directly. Since 2.32

set
void set(void* object)

Change the object to which weak_ref points, or set it to NULL. You must own a strong reference on object while calling this function. Since 2.32 Signal Details The "notify" signal void user_function (GObject *gobject, GParamSpec *pspec, gpointer user_data) : No Hooks The notify signal is emitted on an object when one of its properties has been changed. Note that getting this signal doesn't guarantee that the value of the property has actually changed, it may also be emitted when the setter for the property is called to reinstate the previous value. This signal is typically used to obtain change notification for a single property, by specifying the property name as a detail in the

Variables

gWeakRef
GWeakRef* gWeakRef;

the main Gtk struct

Meta