[Python-Dev] Problems with the Python Memory Manager

Armin Rigo arigo at tunes.org
Thu Nov 24 13:11:13 CET 2005


Hi,

Ok, here is the reason for the leak...

There is in scipy a type called 'int32_arrtype' which inherits from both
another scipy type called 'signedinteger_arrtype', and from 'int'.
Obscure!  This is not 100% officially allowed: you are inheriting from
two C types.  You're living dangerously!

Now in this case it mostly works as expected, because the parent scipy
type has no field at all, so it's mostly like inheriting from both
'object' and 'int' -- which is allowed, or would be if the bases were
written in the opposite order.  But still, something confuses the
fragile logic of typeobject.c.  (I'll leave this bit to scipy people to
debug :-)

The net result is that unless you force your own tp_free as in revision
1490, the type 'int32_arrtype' has tp_free set to int_free(), which is
the normal tp_free of 'int' objects.  This causes all deallocated
int32_arrtype instances to be added to the CPython free list of integers
instead of being freed!


A bientot,

Armin


More information about the Python-Dev mailing list