File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -221,6 +221,12 @@ or request "multi-phase initialization" by returning the definition struct itsel
221
221
than 0 and the module state (as returned by :c:func: `PyModule_GetState `)
222
222
is ``NULL``.
223
223
224
+ Like :c:member:`PyTypeObject.tp_clear`, this function is not *always*
225
+ called before a module is deallocated. For example, when reference
226
+ counting is enough to determine that an object is no longer used,
227
+ the cyclic garbage collector is not involved and
228
+ :c:member:`~PyModuleDef.m_free` is called directly.
229
+
224
230
.. versionchanged:: 3.9
225
231
No longer called before the module state is allocated.
226
232
Original file line number Diff line number Diff line change @@ -1381,6 +1381,12 @@ and :c:type:`PyType_Type` effectively act as defaults.)
1381
1381
so that *self * knows the contained object can no longer be used. The
1382
1382
:c:func: `Py_CLEAR ` macro performs the operations in a safe order.
1383
1383
1384
+ Note that :c:member: `~PyTypeObject.tp_clear ` is not *always * called
1385
+ before an instance is deallocated. For example, when reference counting
1386
+ is enough to determine that an object is no longer used, the cyclic garbage
1387
+ collector is not involved and :c:member: `~PyTypeObject.tp_dealloc ` is
1388
+ called directly.
1389
+
1384
1390
Because the goal of :c:member: `~PyTypeObject.tp_clear ` functions is to break reference cycles,
1385
1391
it's not necessary to clear contained objects like Python strings or Python
1386
1392
integers, which can't participate in reference cycles. On the other hand, it may
You can’t perform that action at this time.
0 commit comments