Newsgroups : Borland : borland.public.delphi.rtl.win32 : 2006 Feb : pls help: reusage of threads stored in an array .. leaks memory?
| Subject: | pls help: reusage of threads stored in an array .. leaks memory? |
| Posted by: | "Klaus Hast" (kha..@arcor.de) |
| Date: | Wed, 8 Feb 2006 22:07:43 |
Hello and good evening,
(yesterday erranously posted to
borland.public.delphi.vcl.components.writing.general)
Delphi4/W98; Delphi6PE/W2k:
I try to process certain file related tasks using threads .... let's say
maybe 0...1000 times.
For not to create a thread for each of those tasks (that will be slower)
- I create 5 threads suspended (without "resume") and store them in an
array,
- start the threads with appropriate arguments and resume them
- when a task is done, before end of execute, a synchronized method in the
main vcl thread will be called
- which suspends the thread
- and restarts ("resume") the next free thread with new arguments
.. until all tasks are finished.
- At form destroy all objects of the array will be freed.
Works well .. but .. even if the execute method - for test - does nothing,
a memory leak seem to happen:
I see that _not_ by means of "AllocMemSize".
I see that by Win98 Resource Display: user and system memory shrinking for
ca 2% after each 5 restarts of the program (each start invoking ca. 30
thread actions, in that sample).
If i replace the thread reusage by individual creation of a thread for each
task (no reusage)
no mem leak happens.
Is my strategy anyhow wrong?
Is this "suspend/resume" approach a guarantee for memory leaks?
Many thanks for any information and advice!
Klaus