[pypy-issue] Issue #2149: Memory leak for Python subclass of cpyext object with non-trivial tp_dealloc (pypy/pypy)
issues-reply at bitbucket.org
Fri Oct 2 16:36:48 CEST 2015
New issue 2149: Memory leak for Python subclass of cpyext object with non-trivial tp_dealloc
As [discussed on IRC](https://botbot.me/freenode/pypy/2015-09-30/?msg=50868264&page=3) and initially reported to [gevent](https://github.com/gevent/gevent/issues/660), if a pure-Python object subclasses a cpyext object that has a non trivial `tp_dealloc` (e.g., it stores additional instance data in its struct), memory can leak. This is because deallocating the pure-Python instance fails to call the `tp_dealloc` of the superclass.
This is easy to demonstrate with Cython, though Cython is not necessary. Given a `base.pxd` like so:
cdef class Base:
cdef public object thing
and a corresponding `base.py` like so:
self.thing = 
compile the cython code and then create a subclass in python:
from base import Base
A tool like objgraph will show that allocating instances of `Sub` leaks a new list each time.
More information about the pypy-issue