13
這是否泄漏?:這PyList_Append(列表,Py_BuildValue(...))泄漏嗎?
static PyObject* foo(PyObject* self, PyObject* args){
PyObect* list = PyList_New(0);
for(int i = 0; i < 100; i++)
// leak? does PyList_Append increment ref of the temporary?
PyList_Append(list, Py_BuildValue("i", 42));
return list;
}
雖然,我想這是更好地做到這一點,在任何情況下?:
static PyObject* foo(PyObject* self, PyObject* args){
PyObect* list = PyList_New(100);
for(int i = 0; i < 100; i++)
PyList_SetItem(list, i, Py_BuildValue("i", 42));
return list;
}
感謝您確認我的懷疑! – James 2010-08-18 13:57:22
python文檔在哪裏發現PyList_Append增加了存儲對象的refcount?我在任何地方都看不到。 – 2017-09-12 18:52:36