@@ -27,57 +27,77 @@ condition that must be true for *B* to occur after *A*.
2727.. raw:: html
2828 :file: lifecycle.dot.svg
2929
30- Explanation:
31-
32- * :c:member:`~ PyTypeObject.tp_new` is called to create a new object .
33- * :c:member:`~ PyTypeObject.tp_alloc` is directly called by
34- :c:member:`~ PyTypeObject.tp_new` to allocate the memory for the new object .
35- * :c:member:`~ PyTypeObject.tp_init` initializes the newly created object .
36- * After :c:member:`!tp_init` completes, the object is ready to use .
37- * Once the object becomes * unreachable* (either no references to the object
38- exist or the object is a member of a :term:`cyclic isolate`):
39-
40- #. :c:member:`~ PyTypeObject.tp_finalize` might be called [2]_ to finalize the
41- object
42- #. :c:member:`~ PyTypeObject.tp_clear` might be called [2]_ to clear references
43- held by the object , if :c:member:`~ PyTypeObject.tp_finalize` was previously
44- called
45- #. :c:member:`~ PyTypeObject.tp_dealloc` is called to destroy the object
46-
47- * The :c:member:`~ PyTypeObject.tp_finalize` function can optionally add a
48- reference to the object , * resurrecting* it and preventing its pending
49- destruction. Python may or may not call :c:member:`!tp_finalize` a second
50- time on a resurrected object; currently :term:`CPython` never calls an
51- object's :c:member:`!tp_finalize` twice.
52- * :c:member:`~ PyTypeObject.tp_dealloc` can optionally call
53- :c:member:`~ PyTypeObject.tp_finalize` via
54- :c:func:`PyObject_CallFinalizerFromDealloc` if it wishes to reuse that code to
55- help with object destruction. This is recommended because it guarantees that
56- :c:member:`!tp_finalize` is always called before destruction.
57- * When :c:member:`~ PyTypeObject.tp_dealloc` finishes object destruction, it
58- directly calls :c:member:`~ PyTypeObject.tp_free` to deallocate the memory.
59-
60- If the object is marked as supporting garbage collection (the
61- :c:macro:`Py_TPFLAGS_HAVE_GC` flag is set in
62- :c:member:`~ PyTypeObject.tp_flags`), the following events are also possible:
63-
64- * The garbage collector occasionally calls
65- :c:member:`~ PyTypeObject.tp_traverse` to identify :term:`cyclic isolates
66- <cyclic isolate> `.
67- * When the garbage collector discovers a :term:`cyclic isolate`, it finalizes
68- one of the objects in the group by calling its
69- :c:member:`~ PyTypeObject.tp_finalize` function. This repeats until the
70- cyclic isolate doesn't exist or all of the objects have been finalized.
71- * :c:member:`~ PyTypeObject.tp_finalize` can resurrect the object by adding a
72- reference from outside the :term:`cyclic isolate`. The new reference causes
73- the group of objects to no longer form a cyclic isolate (the reference cycle
74- may still exist, but the objects are no longer isolated).
75- * When the garbage collector discovers a :term:`cyclic isolate` and all of the
76- objects in the group have already been finalized, the garbage collector clears
77- one or more of the uncleared objects in the group (possibly concurrently) by
78- calling each's :c:member:`~ PyTypeObject.tp_clear` function. This repeats as
79- long as the cyclic isolate still exists and not all of the objects have been
80- cleared.
30+ .. raw:: html
31+
32+ <script >
33+ (() => {
34+ const g = document .getElementById ('life _events _graph ');
35+ const title = g .querySelector (':scope > title' );
36+ title.id = ' life-events-graph-title' ;
37+ const svg = g .closest ('svg ');
38+ svg .role = 'img ';
39+ svg .setAttribute ('aria-describedby ',
40+ 'life-events-graph-description ');
41+ svg .setAttribute ('aria-labelledby ', 'life-events-graph-title ');
42+ })();
43+ </script >
44+
45+ .. container::
46+ :name: life-events-graph-description
47+
48+ Explanation:
49+
50+ * :c:member:`~ PyTypeObject.tp_new` is called to create a new object .
51+ * :c:member:`~ PyTypeObject.tp_alloc` is directly called by
52+ :c:member:`~ PyTypeObject.tp_new` to allocate the memory for the new
53+ object .
54+ * :c:member:`~ PyTypeObject.tp_init` initializes the newly created object .
55+ * After :c:member:`!tp_init` completes, the object is ready to use .
56+ * Once the object becomes * unreachable* (either no references to the object
57+ exist or the object is a member of a :term:`cyclic isolate`):
58+
59+ #. :c:member:`~ PyTypeObject.tp_finalize` might be called [2]_ to finalize
60+ the object
61+ #. :c:member:`~ PyTypeObject.tp_clear` might be called [2]_ to clear
62+ references held by the object , if :c:member:`~ PyTypeObject.tp_finalize`
63+ was previously called
64+ #. :c:member:`~ PyTypeObject.tp_dealloc` is called to destroy the object
65+
66+ * The :c:member:`~ PyTypeObject.tp_finalize` function can optionally add a
67+ reference to the object , * resurrecting* it and preventing its pending
68+ destruction. Python may or may not call :c:member:`!tp_finalize` a second
69+ time on a resurrected object; currently :term:`CPython` never calls an
70+ object's :c:member:`!tp_finalize` twice.
71+ * :c:member:`~ PyTypeObject.tp_dealloc` can optionally call
72+ :c:member:`~ PyTypeObject.tp_finalize` via
73+ :c:func:`PyObject_CallFinalizerFromDealloc` if it wishes to reuse that
74+ code to help with object destruction. This is recommended because it
75+ guarantees that :c:member:`!tp_finalize` is always called before
76+ destruction.
77+ * When :c:member:`~ PyTypeObject.tp_dealloc` finishes object destruction, it
78+ directly calls :c:member:`~ PyTypeObject.tp_free` to deallocate the memory.
79+
80+ If the object is marked as supporting garbage collection (the
81+ :c:macro:`Py_TPFLAGS_HAVE_GC` flag is set in
82+ :c:member:`~ PyTypeObject.tp_flags`), the following events are also possible:
83+
84+ * The garbage collector occasionally calls
85+ :c:member:`~ PyTypeObject.tp_traverse` to identify :term:`cyclic isolates
86+ <cyclic isolate> `.
87+ * When the garbage collector discovers a :term:`cyclic isolate`, it
88+ finalizes one of the objects in the group by calling its
89+ :c:member:`~ PyTypeObject.tp_finalize` function. This repeats until the
90+ cyclic isolate doesn't exist or all of the objects have been finalized.
91+ * :c:member:`~ PyTypeObject.tp_finalize` can resurrect the object by adding a
92+ reference from outside the :term:`cyclic isolate`. The new reference
93+ causes the group of objects to no longer form a cyclic isolate (the
94+ reference cycle may still exist, but the objects are no longer isolated).
95+ * When the garbage collector discovers a :term:`cyclic isolate` and all of
96+ the objects in the group have already been finalized, the garbage
97+ collector clears one or more of the uncleared objects in the group
98+ (possibly concurrently) by calling each's
99+ :c:member:`~ PyTypeObject.tp_clear` function. This repeats as long as the
100+ cyclic isolate still exists and not all of the objects have been cleared.
81101
82102
83103Cyclic Isolate Destruction
0 commit comments