I have written a program in Delphi 2007 using the OmniThreadLibrary. I found that the program was growing bigger and bigger in memory as it ran using the following structure to launch tasks.
class procedure saveIniFile(const iniFile: TStringList);
var
task : IOmniTaskControl;
begin
task := CreateTask(saveIniFileTask, 'saveIniFile')
.SetParameter('iniFile', iniFile)
.Unobserved
.Schedule;
end;
After reading a few blogs and looking through docs, I found that I needed to store an instance of the task in a persistent variable. Ie...
var
task : IOmniTaskControl;
class procedure saveIniFile(const iniFile: TStringList);
begin
task := CreateTask(saveIniFileTask, 'saveIniFile')
.SetParameter('iniFile', iniFile)
.Unobserved
.Schedule;
end;
My question is, should this be a separate persistent variable for each instance of the task?
For example: if I launched the same task from within a loop, would each previous instance would be overwritten by the new and therefore would I need an array of instances?
The examples I have seen seem to use a single variable for all instances created but this seem wrong.
Can anyone shed any light?
Thanks