[Python-Dev] tp_dealloc
Greg Ewing
greg.ewing at canterbury.ac.nz
Tue Jun 1 02:33:23 CEST 2010
smarv at gmx.net wrote:
> Now, the problem is, Python appears to read-access the deallocated memory
> still after tp_dealloc.
It's not clear exactly what you mean by "after tp_dealloc".
The usual pattern is for a type's tp_dealloc method to call
the base type's tp_dealloc, which can make further references
to the object's memory. At the end of the tp_dealloc chain,
tp_free gets called, which is what actually deallocates the
memory.
I would say your tp_dealloc shouldn't be modifying anything
in the object struct that your corresponding tp_alloc method
didn't set up, because code further along the tp_dealloc
chain may rely on it. That includes fields in the object
header.
--
Greg
More information about the Python-Dev
mailing list