[Numpy-discussion] creating a Numeric array from a numpy array LEAKS memory

Peter numpy-discussion at maubp.freeserve.co.uk
Fri Oct 24 15:05:01 EDT 2008


On Fri, Oct 24, 2008 at 7:52 PM, Pauli Virtanen <pav at iki.fi> wrote:
> Yep, leaks also here: (Numeric 24.2, numpy 1.2.0)
>
>        import sys, numpy, Numeric
>        na = numpy.array([0.0])
>        for i in xrange(1000000):
>            foo = Numeric.array(na, Numeric.Float)
>        print sys.getrefcount(na)
>
> The getrefcount prints 1000002, so it seems like there's a refcount error
> somewhere.

Same leak here using Numeric 24.2 and numpy 1.0.1 on Linux.

> But
>
>        na = numpy.array([0.0])
>        for i in xrange(1000000):
>            foo = numpy.array(na, numpy.float_)
>        print sys.getrefcount(na)
>
> refcounts correctly.

Also fine.  And for the record using the intermediate list also works for me:

import sys, numpy, Numeric
na = numpy.array([0.0])
na_list = list(na)
for i in xrange(1000000):
     foo = Numeric.array(na_list, Numeric.Float)
print sys.getrefcount(na)

Peter



More information about the NumPy-Discussion mailing list