memory leak in python extension; mysqlclient & numpy
John Hunter
jdhunter at nitace.bsd.uchicago.edu
Wed Oct 9 14:19:16 EDT 2002
>>>>> "John" == John Hunter <jdhunter at ace.bsd.uchicago.edu> writes:
John> I am writing a python extension to load some data from a
John> mysql database directly into some numpy arrays. There is a
John> memory leak, which I see when running top while repeatedly
John> calling the function get_quotes included below. Can anyone
John> offer some advice about where this leak is occurring?
OK, found the leak. The problem is that I need Py_DECREF my arrays
after building them into the tuple for return, as in
PyArrayObject *p,*v,*t;
PyObject *tup;
[ snip ]
p = (PyArrayObject *)PyArray_FromDims(1,dimensions,PyArray_FLOAT);
v = (PyArrayObject *)PyArray_FromDims(1,dimensions,PyArray_INT);
t = (PyArrayObject *)PyArray_FromDims(1,dimensions,PyArray_LONG);
[ snip ]
tup = Py_BuildValue("(OOO)", p,v,t);
Py_DECREF(p);
Py_DECREF(t);
Py_DECREF(v);
return tup;
Live and learn....
JDH
More information about the Python-list
mailing list