0

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

Gavin
  • 2,123
  • 1
  • 15
  • 19
  • You've read this http://www.thedelphigeek.com/2009/11/omnithreadlibrary-patterns-task.html I presume – David Heffernan Sep 19 '14 at 20:21
  • @DavidHeffernan - Yes, I think that OmniThreadLibrary is great but the docs are a bit confusing. I used .Unobserved but the threads didn't seem to free up resources so the app was growing in memory and slowing down. – Gavin Sep 19 '14 at 20:28
  • How are the tasks going to be released? You appear to be asking for them not to be? Why did you want them to be unobserved? – David Heffernan Sep 19 '14 at 20:31
  • This is where I'm getting confused... If they are Unobserved, should I just create a task and not store the instance (global or local)? If I do store the instance (which would be handy to do some other clean up tasks), does each call to CreateTask be stored in a separate persistent variable? – Gavin Sep 19 '14 at 20:32
  • You need to take an explicit and conscious decision on how to clean up these tasks. The document I linked to has various examples. – David Heffernan Sep 19 '14 at 20:35

0 Answers0