[SciPy-Dev] memory leak in scipy.fftpack.ifft2!

Brian Toby brian.toby@anl....
Sun Mar 25 16:48:05 CDT 2012

> I feel I should point out that they are only "reused" up to a point:
> sf.ifft2 is here returning an array *that ifft2 is allocating*. 

True enough, but before the output array is copied over the input array and the
output array will then be unreferenced and be a candidate for cleanup. 

> You can force a garbage collection at every iteration by sticking
> "gc.collect()" in the loop.

Good suggestion. That would show a memory leak, as opposed to a lag in garbage
collection. Indeed when I strip the script down and do that (see below), I still
see the memory use grow on every iteration, now by 256Mb. This stranded block
has a different address than the one returned by ifft2, but that is the only
routine that could be creating it.

import numpy as np
import scipy.fftpack as sf
import pdb
import gc
from numpy.version import version as np_version
from scipy.version import version as sp_version
print "numpy %s; scipy %s" % (np_version, sp_version)

ref = np.random.rand(4096,4096)
for ii in range(1,20):
    print 'loop=',ii
    ffta = sf.fft2(ref)
    print 'ffta address=',hex(ffta.ctypes.data)[2:]

I found the trak site and put in a ticket.

More information about the SciPy-Dev mailing list