The attached program leaks about 24 bytes per loop. The comments give a bit more detail as to when the leak occurs and doesn't. How can I track down where this leak is actually coming from?

Here is a sample run on my machine:

$ python simple.py
Python Version:  2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3]
numpy version:  1.6.1
/etc/lsb-release:
   DISTRIB_ID=Ubuntu
   DISTRIB_RELEASE=12.04
   DISTRIB_CODENAME=precise
   DISTRIB_DESCRIPTION="Ubuntu 12.04 LTS"
110567424.0 24.465408
135168000.0 24.600576
159768576.0 24.600576
184369152.0 24.600576
208969728.0 24.600576
233570304.0 24.600576
258035712.0 24.465408
282636288.0 24.600576
307236864.0 24.600576
331837440.0 24.600576
import numpy as np
import os
import sys

def get_memsize():
    """ Returns current process memory size in bytes
    """
    pagesize = os.sysconf("SC_PAGE_SIZE")
    with open('/proc/self/statm') as statm:
        mem=float( statm.readline().split()[0] )*pagesize
    return mem

print "Python Version: ", sys.version
print "numpy version: ", np.__version__
with open("/etc/lsb-release") as rel:
    print "/etc/lsb-release: "
    for line in rel:
        print "  ", line,
# create numpy arrays
a = np.zeros(dtype=[('f', 'f8')], shape=tuple())
b = np.zeros(shape=(1,))
# create a counter, can be integer or float
f = 0
# create a constant value
i = 0
memory=get_memsize()
while True:
    f += 1

    # these leak
    a['f'] = f
    #b[:] = f

    # these do not leak
    #b[0] = f
    #b[:] = 0
    #a['f'] = i
    #a['f'] = 0

    # if there is no assignment to an array
    # there is no leak

    # this just prints the current memory
    # and average per-assignement delta in bytes
    if f>=1e6:
        newmemory = get_memsize()
        print newmemory, (newmemory-memory)/f
        memory = newmemory
        f=0

_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to