weakref.finalize()
weakref.finalize() is a Python function in the Weakref Module category. Registers a finalizer function to be called when obj is garbage collected. The syntax is weakref.finalize(obj, func, *args, **kwargs). Returns: Finalize object. A typical example: weakref.finalize(obj, print, "object finalized"). A close sibling is weakref.ref(), which creates a weak reference object. Call .deref() to get the object or None if collected. A close sibling is weakref.proxy(), which creates a weak reference proxy that acts like the original object. A close sibling is weakref.WeakValueDictionary(), which a dictionary that holds weak references to its values. A close sibling is weakref.WeakKeyDictionary(), which a dictionary that holds weak references to its keys. More about this category: Weak references — ref, proxy, WeakValueDictionary, WeakSet. Related Weakref Module entries: weakref.ref(), weakref.proxy(), weakref.WeakValueDictionary(), weakref.WeakKeyDictionary(), weakref.WeakSet(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.