[Numpy-discussion] ndarray subclass causes memory leak

Jeremy Mayes jeremy.mayes@gmail....
Fri Aug 14 06:39:21 CDT 2009

This simple example causes a massive leak in v1.3.0 which didn't exist in
v1.0.1.  What am I doing wrong?  If I replace
arr = [Array((2,2)), Array((2,2))]


arr = [numpy.ndarray((2,2,)), numpy.ndarray((2,2))]

then I don't have the leak

import numpy
import gc

 class Array(numpy.ndarray):
def __new__(subtype, shape, dtype=float, buffer=None, offset=0,
strides=None, order=None, info=None):
return numpy.ndarray.__new__(subtype, shape, dtype, buffer, offset, strides,

def __array_finalize__(self, obj):
print 'called array_finalize'

if __name__=='__main__':
arr = [Array((2,2)), Array((2,2))]

nbytesAllocated = 0
 for i in xrange(1000000000):
a = numpy.array(arr)
nbytesAllocated += a.nbytes
 if i%1000 == 0:
print 'allocted %s'%nbytesAllocated



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090814/81fc5e59/attachment.html 

More information about the NumPy-Discussion mailing list