| 1 |
Weak References |
| 2 |
=============== |
| 3 |
|
| 4 |
While Python has a builtin ``weakref`` module it only allows one to create |
| 5 |
weak references to Python objects, but with PyGObject the Python object |
| 6 |
"wrapping" a GObject and the GObject itself might not have the same lifetime. |
| 7 |
The wrapper can get garbage collected and a new wrapper created again at a |
| 8 |
later point. |
| 9 |
|
| 10 |
If you want to get notified when the underlying GObject gets finalized use |
| 11 |
:meth:`GObject.Object.weak_ref`: |
| 12 |
|
| 13 |
|
| 14 |
.. method:: GObject.Object.weak_ref(callback, *user_data) |
| 15 |
|
| 16 |
Registers a callback to be called when the underlying GObject gets |
| 17 |
finalized. The callback will receive the given `user_data`. |
| 18 |
|
| 19 |
To unregister the callback call the ``unref()`` method of the returned |
| 20 |
GObjectWeakRef object. |
| 21 |
|
| 22 |
:param callback: A callback which will be called when the object |
| 23 |
is finalized |
| 24 |
:type callback: :func:`callable` |
| 25 |
:param user_data: User data that will be passed to the callback |
| 26 |
:returns: GObjectWeakRef |