You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using an ndarray as an arg to a cdef function, and that ndarray is not used in the function, that object is never properly garbage collected and causes a memory leak.
If the ndarray is used in the function, it is collected properly.
Reproducing code example:
memleak.pyx
import numpy as np
cimport numpy as cnp
from numpy cimport ndarray
cnp.import_array()
cdef inline void caller():
cdef:
ndarray[int] x
x = np.asarray(range(10000))
dont_use_x(x)
cdef inline void dont_use_x(ndarray[int] x):
pass
while True:
caller()
setup.py:
from distutils.core import setup
from Cython.Build import cythonize
import numpy
setup(
ext_modules = cythonize("memleak.pyx"),
include_dirs=[numpy.get_include()]
)
When using an ndarray as an arg to a
cdef
function, and thatndarray
is not used in the function, that object is never properly garbage collected and causes a memory leak.If the
ndarray
is used in the function, it is collected properly.Reproducing code example:
memleak.pyx
setup.py:
to run:
Numpy/Python version information:
1.16.2 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)]
The text was updated successfully, but these errors were encountered: