13
Liệu rò rỉ này ?:Điều này PyList_Append (danh sách, Py_BuildValue (...)) bị rò rỉ?
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;
}
Mặc dù, tôi cho rằng nó tốt hơn để làm điều này, trong bất kỳ trường hợp ?:
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;
}
Cảm ơn bạn đã xác nhận sự nghi ngờ của mình! – James
Tài liệu python nào tìm thấy PyList_Append tăng số lần truy cập của đối tượng được lưu trữ? Tôi không thấy ở đâu cả. –