program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils,
Classes,
System.syncobjs,
PythonEngine;
type
th = class(TPythonThread)
protected
procedure Execute; Override;
public
constructor create(createsuspended:boolean);
end;
var
cs:TcriticalSection;
{ th }
constructor th.create(createsuspended: boolean);
begin
inherited Create(CreateSuspended);
//ThreadExecMode := emNewInterpreter;
FreeOnTerminate:=True;
end;
procedure th.Execute;
var
val:string;
PythonEngine1:TPythonEngine;
begin
inherited;
while true do begin
PythonEngine1:=TPythonEngine.Create(nil);
PythonEngine1.InitThreads:=True;
PythonEngine1.AutoLoad:= False;
PythonEngine1.AutoFinalize:=False;
PythonEngine1.AutoUnload:=False;
PythonEngine1.RedirectIO:=False;
PythonEngine1.LoadDll;
PythonEngine1.ExecString('fun=("Hello World")');
val:=(PythonEngine1.EvalStringAsStr('fun'));
PythonEngine1.UnloadDll;
FreeAndNil(PythonEngine1); // or .Free
cs.Enter;
Write(Format(#13'VALUE=%s',[val]));
cs.Leave;
if not Terminated then
Terminate;
DoTerminate;
end;
end;
var
i:integer;
begin
//ReportMemoryLeaksOnShutdown:=True;
cs:=TcriticalSection.Create;
for i:=0 to 1 do
th.create(false);
readln;
end.
hello on your resource that you suggested to me https://en.delphipraxis.net/topic/8189-python4delphi-memory-leaks/?do=findComment&comment=69149 no one can help me, so I decided to write here. I'm having huge memory leaks when using a component in threads here is the whole code i am using below :
Checked on the newest component update !