Jump to content
FGAIL87

Memory leak with PyBytes_AsStringAndSize

Recommended Posts

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×