https://github.com/python/cpython/blob/master/Include/objimpl.h#L83说
PyObject_Realloc(p != NULL, 0) does not return NULL, or free the memory at p.
PyObject_Realloc不会释放内存
我注意到我的程序内存泄漏,它时不时地使用PyObject_Realloc
我尝试使用以下方法修复它:
PyLongObject *new = (PyLongObject *) PyObject_Realloc(obj, new_size);
if (new == NULL) {
return PyErr_NoMemory();
}
if (new != obj) {
PyObject_Free(obj);
}
obj = new;
但是现在我得到了malloc错误pointer being freed was not allocated
在使用PyObject_Malloc和PyObject_Realloc时,如何确保我的程序不会泄漏内存
您需要以与使用
realloc
完全相同的方式使用它:相关问题 更多 >
编程相关推荐