summaryrefslogtreecommitdiffstats
path: root/Doc/extending
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/extending')
-rw-r--r--Doc/extending/newtypes.rst14
1 files changed, 13 insertions, 1 deletions
diff --git a/Doc/extending/newtypes.rst b/Doc/extending/newtypes.rst
index 6e17897..23ec8bc 100644
--- a/Doc/extending/newtypes.rst
+++ b/Doc/extending/newtypes.rst
@@ -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::