I write a c++ extension function below, in this code, I have a buffer from heap(buf),and it content will copy to python memory_view object, finally I called buf.release() to make python gc own this buf.
Then memory leak happend, but when I do not call buf.release(), python will get not correct content.What can I do in this situation? Tks.
I think the problem is that you're creating and storing a memory view of a buffer that Python knows nothing about. It's your responsibility to free the buffer when it's no longer needed. buf.release() merely releases the ownership and returns the address of the pointer; Python still won't know anything about it!
You could try making a bytes object from the contents of the buffer and then store that instead of a memory view.
qiuyang163 commentedSep 5, 2022
•
edited
Bug report
I write a c++ extension function below, in this code, I have a buffer from heap(buf),and it content will copy to python memory_view object, finally I called buf.release() to make python gc own this buf.
Then memory leak happend, but when I do not call buf.release(), python will get not correct content.What can I do in this situation? Tks.
Your environment
The text was updated successfully, but these errors were encountered: