[Numpy-discussion] reference leacks in numpy.asarray

Lisandro Dalcin dalcinl at gmail.com
Thu Aug 2 15:22:07 EDT 2007


using numpy-1.0.3, I believe there are a reference leak somewhere.
Using a debug build of Python 2.5.1 (--with-pydebug), I get the
following

import sys, gc
import numpy

def testleaks(func, args=(), kargs={}, repeats=5):
    for i in xrange(repeats):
        r1 = sys.gettotalrefcount()
        func(*args,**kargs)
        r2 = sys.gettotalrefcount()
        rd = r2-r1
        print 'before: %d, after: %d, diff: [%d]' % (r1, r2, rd)

def npy_asarray_1():
    a = numpy.zeros(5, dtype=int)
    b = numpy.asarray(a, dtype=float)
    del a, b

def npy_asarray_2():
    a = numpy.zeros(5, dtype=float)
    b = numpy.asarray(a, dtype=float)
    del a, b

if __name__ == '__main__':
    testleaks(npy_asarray_1)
    testleaks(npy_asarray_2)


$ python npyleaktest.py
before: 84531, after: 84532, diff: [1]
before: 84534, after: 84534, diff: [0]
before: 84534, after: 84534, diff: [0]
before: 84534, after: 84534, diff: [0]
before: 84534, after: 84534, diff: [0]
before: 84531, after: 84533, diff: [2]
before: 84535, after: 84536, diff: [1]
before: 84536, after: 84537, diff: [1]
before: 84537, after: 84538, diff: [1]
before: 84538, after: 84539, diff: [1]

It seems npy_asarray_2() is leaking a reference. I am  missing
something here?. The same problem is found in C, using
PyArray_FROM_OTF (no time to go inside to see what's going on, sorry)

If this is know and solved in SVN, please forget me.

Regards,


-- 
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594



More information about the NumPy-Discussion mailing list