weakref — Weak references — Python 3.11.16 documentation

docs.python.org

Tin mới

Comparing finalizers with __del__() methods¶

Suppose we want to create a class whose instances represent temporary directories. The directories should be deleted with their contents when the first of the following events occurs:

array — Efficient arrays of numeric values

types — Dynamic type creation and names for built-in types

Python Module Index

3.11.16 Documentation

The Python Standard Library

garbage collection

The weakref module allows the Python programmer to create weak references to objects.

Weak Reference Objects¶

The weakref module allows the Python programmer to create weak references to objects.

Weak Reference Support

The weakref module allows the Python programmer to create weak references to objects.

atexit: Register and execute cleanup functions.

Return a callable finalizer object which will be called when obj is garbage collected. Unlike an ordinary weak reference, a finalizer will always survive until the reference object is collected, greatly simplifying lifec

Weak Reference Objects¶

Weak reference objects have no methods and no attributes besides ref.__callback__. A weak reference object allows the referent to be obtained, if it still exists, by calling it: