A second example of memory usage/leaks on linux using TTask (but only running one at a time) inside a loop will show memory usage increasing depending on how big you make the for loop. In this example is used 21.9Mib on Linux and this never seems to go away. On Windows memory usage stays the same. If you make the loop bigger it just keeps growing and growing.
A second example of memory usage/leaks on linux using TTask (but only running one at a time) inside a loop will show memory usage increasing depending on how big you make the for loop. In this example is used 21.9Mib on Linux and this never seems to go away. On Windows memory usage stays the same. If you make the loop bigger it just keeps growing and growing.
program TTaskMemLeak;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.Classes,
System.Threading in 'C:\Program Files (x86)\Embarcadero\Studio\19.0\source\rtl\common\System.Threading.pas';
procedure newTask( value: integer );
var
myTask: ITask;
begin
myTask := TTask.run( procedure()
begin
//sleep(10);
end );
myTask.wait(20000);
myTask := nil;
end;
var
i: integer;
begin
try
writeLn('Loop starting' );
for i := 0 to 100000 do
begin
newTask( i );
if (i = 10000) then
begin
writeLn('Loop done' );
sleep(5000); //Memory used by tasks is all still in play here
end;
end;
//Memory is cleared here
writeLn('Loop complete' );
readLn;
halt(0);
{ TODO -oUser -cConsole Main : Insert code here }
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
program TTaskMemLeak;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.Classes,
System.Threading in 'C:\Program Files (x86)\Embarcadero\Studio\19.0\source\rtl\common\System.Threading.pas';
procedure newTask( value: integer );
var
myTask: ITask;
begin
myTask := TTask.run( procedure()
begin
//sleep(10);
end );
myTask.wait(20000);
myTask := nil;
end;
var
i: integer;
begin
try
writeLn('Loop starting' );
for i := 0 to 100000 do
begin
newTask( i );
if (i = 10000) then
begin
writeLn('Loop done' );
sleep(5000); //Memory used by tasks is all still in play here
end;
end;
//Memory is cleared here
writeLn('Loop complete' );
readLn;
halt(0);
{ TODO -oUser -cConsole Main : Insert code here }
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
just wondering why its
ReplyDeletevar
myTask: ITask;
and not
var
myTask: TTask;
An update as requested, firstly this test uses 2.5 MiB of Memory
ReplyDeleteprocedure testTaskLoopProc;
procedure newTask( value: integer );
var
myTask: ITask;
begin
myTask := TTask.run( procedure()
begin
sleep( 1 );
end );
myTask.wait(20000);
myTask := nil;
end;
var
i: integer;
begin
for i := 0 to 10000 do
begin
newTask( i );
if (i = 10000) then
begin
writeLn('Loop done' );
sleep(5000); //Memory used by tasks is all still in play here
end;
end;
end;
Comment out //myTask.wait(20000); and it uses 16Mib of Memory
ReplyDelete