I wrote a simple Python extension module to simulate a 3-bit analog-to-digital converter. It is supposed to accept a floating-point array as its input to return the same size ar
The problem is not with PyArray_SimpleNewFromData
which produces a properly refcounted PyObject*
. Rather, it's with your malloc
, assigned to pout
then never free
d.
As the docs at http://docs.scipy.org/doc/numpy/user/c-info.how-to-extend.html clearly state, documenting PyArray_SimpleNewFromData
:
the
ndarray
will not own its data. When thisndarray
is deallocated, the pointer will not be freed. ... If you want the memory to be freed as soon as thendarray
is deallocated then simply set theOWNDATA
flag on the returnedndarray
.
(my emphasis on the not). IOW, you're observing exactly the "will not be freed" behavior so clearly documented, and are not taking the step specifically recommended should you want to avoid said behavior.