On Friday 26 October 2007 05:39, Robert Crida wrote:
I recently posted about a memory leak in numpy and failed to mention the version. The leak manifests itself in numpy-1.0.3.1 but is not present in numpy-1.0.2
The following code reproduces the bug:
import numpy as np
a = np.array([1.0, 2.0, 3.0]) while True: b = str(a)
What happens above is that is repeatedly converted to a string. The process size grow quite rapidly.
Has anyone else come across this? Where do I look to try to correct it?
Debugging exposes numpy.core.umath.seterrobj as the source, so you can get even faster memory growth with this (around 30MB/s on my machine): import numpy pyvals = numpy.core.umath.geterrobj() while True: numpy.core.umath.seterrobj(pyvals) That is actually ufunc_seterr in trunk/numpy/core/src/ufuncobject.c... which calls ufunc_update_use_defaults as of r3040. A call to Py_DECREF(errobj) is missing there after calling PyUFunc_GetPyValues. So using the following patch on the current svn revision of ufuncobject.c should fix this leak: 3206a3207
Py_DECREF(errobj);
Cheers, Karol -- written by Karol Langner Sun Oct 28 20:00:47 EDT 2007