Reputation: 41
I have a piece of C++ code with python-C++ interface that need to be called repeatedly with a python list as its input. I found even the dummy process as following leads to memory leak:
In python:
a = [1.0]*1000
for c in range(1000):
dummy(a, 1)
In C++:
static PyObject* dummy(PyObject* self, PyObject* args) {
Py_RETURN_NONE;
}
Am I miss anything here so it introduces memory leak?
Upvotes: 4
Views: 436
Reputation: 30216
No that's fine, objects you get passed to your c method are only borrowed, i.e. you don't have to decrease the refcount of the objects before returning (as a matter of fact that would be a bad, bad bug).
See for example this part of the documentation:
Note that any Python object references which are provided to the caller are borrowed references; do not decrement their reference count!
How are you even determining that you have a memory leak? It's more than likely that that's your problem.
Upvotes: 1