File: weakrefs.rst

package info (click to toggle)
pygobject 3.54.5-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,864 kB
  • sloc: ansic: 40,281; python: 26,363; sh: 477; makefile: 81; xml: 35; cpp: 1
file content (26 lines) | stat: -rw-r--r-- 978 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Weak References
===============

While Python has a builtin ``weakref`` module it only allows one to create
weak references to Python objects, but with PyGObject the Python object
"wrapping" a GObject and the GObject itself might not have the same lifetime.
The wrapper can get garbage collected and a new wrapper created again at a
later point.

If you want to get notified when the underlying GObject gets finalized use
:meth:`GObject.Object.weak_ref`:


.. method:: GObject.Object.weak_ref(callback, *user_data)

    Registers a callback to be called when the underlying GObject gets
    finalized. The callback will receive the give `user_data`.

    To unregister the callback call the ``unref()`` method of the returned
    GObjectWeakRef object.

    :param callback: A callback which will be called when the object
        is finalized
    :type callback: :func:`callable`
    :param user_data: User data that will be passed to the callback
    :returns: GObjectWeakRef