mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
bpo-28737: Document when tp_dealloc should call PyObject_GC_UnTrack() (GH-29246)
Objects that support garbage collection ("container" objects) should
call PyObject_GC_UnTrack() from their destructors before clearing any
fields which may point to other "container" objects.
This commit is contained in:
parent
4776b07d17
commit
35e1ff38ee
3 changed files with 33 additions and 9 deletions
|
|
@ -73,7 +73,19 @@ function::
|
|||
newdatatype_dealloc(newdatatypeobject *obj)
|
||||
{
|
||||
free(obj->obj_UnderlyingDatatypePtr);
|
||||
Py_TYPE(obj)->tp_free(obj);
|
||||
Py_TYPE(obj)->tp_free((PyObject *)obj);
|
||||
}
|
||||
|
||||
If your type supports garbage collection, the destructor should call
|
||||
:c:func:`PyObject_GC_UnTrack` before clearing any member fields::
|
||||
|
||||
static void
|
||||
newdatatype_dealloc(newdatatypeobject *obj)
|
||||
{
|
||||
PyObject_GC_UnTrack(obj);
|
||||
Py_CLEAR(obj->other_obj);
|
||||
...
|
||||
Py_TYPE(obj)->tp_free((PyObject *)obj);
|
||||
}
|
||||
|
||||
.. index::
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue