thouis / numpy-trac-migration

numpy Trac to github issues migration
2 stars 3 forks source link

Memory leak in numpy? (Trac #2125) #5921

Open numpy-gitbot opened 11 years ago

numpy-gitbot commented 11 years ago

Original ticket http://projects.scipy.org/numpy/ticket/2125 on 2012-05-02 by trac user eschlafly, assigned to unknown.

Under numpy 1.6.0, the following code leaks about a hundred megs of memory for me:

import numpy
dtype = [('var1', '100f8')]
for i in xrange(100000):
    arr = numpy.zeros(1, dtype=[('var1_holder', dtype)])
    arr['var1_holder'] = numpy.zeros(1, dtype=dtype)[0]

Admittedly, this code should probably trigger some kind of exception anyway. Rewriting the code slightly as below gets rid of the leak:

    arr['var1_holder'][0] = numpy.zeros(1, dtype=dtype)

Still, I would much rather have had an exception thrown than a silent memory leak in otherwise well-behaving code.