|Subject:||Thread object leak|
|Posted by:||mikk (firstname.lastname@example.org)|
|Date:||Tue, 27 Mar 2007|
I have got a problem with my TThread descendant. The MemCheck reports
memory leak on thread object instance which I create. Since I'm setting
FreeOnTerminate := True to avoid WaitFor synchro hell, I don't call the
destructor, intentionally. But it seems there is a problem with that.
I use the thread just like this:
myThread := TMyThread.Create(True); // <<-- MemCheck log shows leak here
myThread.FreeOnTerminate := True;
// Long operations - Here I'm posting messages to the
// message queue of the thread to process data in background
// Usually there should stand myThread.Free(),
// but since its FreeOnTerminate = True, it should
// be freed by itself when Execute() ends.
// When I call Free() or WaitFor() and Free(),
// then I have a deadlock.
I use Delphi 7 (patched). What can I do to avoid this leak ???
Thanks in advance,