Supporting Cyclic Garbage Collection — Python 3.16.0a0 documentation

docs.python.org

Tin mới

Type Object Structures

API and ABI Versioning

Python Module Index

3.16.0a0 Documentation

Python/C API reference manual

Object Implementation Support

PyType_FromSpecWithBases()

The object’s memory must be deallocated using PyObject_GC_Del().

Python object header

Analogous to PyObject_GC_New but allocates extra_size bytes at the end of the object (at offset tp_basicsize). The allocated memory is initialized to zeros, except for the Python object header.

PyObject_VisitManagedDict()

A typical tp_traverse function calls the Py_VISIT() convenience macro on each of the instance’s members that are Python objects that the instance owns. For example, this is a (slightly outdated) traversal function for th

gc: Interface to the cycle-detecting garbage collector.

The Py_VISIT() call may be skipped for those members that provably cannot participate in reference cycles. In the local_traverse example above, there is also a self->key member, but it can only be NULL or a Python string

borrowed references

The following functions should only be used in a tp_traverse handler; calling them in other contexts may have unintended consequences.

PyModule_GetState()

PyObject_GetTypeData(), PyObject_GetItemData(), PyType_GetModuleState(), PyModule_GetState(), PyModule_GetToken(), PyType_GetBaseByToken()

sys.unraisablehook

Perform a full garbage collection, if the garbage collector is enabled. (Note that gc.collect() runs it unconditionally.)