FGAIL87 0 Posted March 18, 2022 Hello, I have a program in Delphi that gets the stream from a camera managed in Python. I get the camera image using the following function GetPythonEngine.PyBytes_AsStringAndSize(camera.ValueObject,P,Len); And I notice that there is a memory leak every time this function is called. Specifically with the function GetPythonEngine.PyBytes_Check(camera.ValueObject); which is used by PyBytes_AsStringAndSize Is anyone observing the same thing? How can I solve the problem? Is there any other way to get the address and size of the camera variable? Share this post Link to post
SwiftExpat 65 Posted March 18, 2022 Have you tried to finalize the variable? You have to call finalize before free. In my constructor: constructor TSERTCPythonEngine.Create; begin inherited Create(true); PE := TPythonEngine.Create(nil); PythonIO := TPythonInputOutput.Create(nil); PythonResultVar := TPythonDelphiVar.Create(nil); end In my destructor destructor TSERTCPythonEngine.Destroy; begin PythonIO.Free; PyMod.Free; PythonResultVar.Finalize; // prevent memory leak PythonResultVar.Free; PE.Free; inherited; end; Share this post Link to post
FGAIL87 0 Posted March 18, 2022 My TPythonDelphiVar and TPythonEngine variables are only destroyed when the program is closed. So there is no problem on this side. The memory leak happens every time the PyBytes_Check function is called. I see the program's memory increasing on the simple call of this function. I'll try to use the solution with PIL mentioned below, which I had left aside. Share this post Link to post