Article View: borland.public.cppbuilder.nativeapi
Article #9239Re: Thread and memory
From: Sara T.
Date: Tue, 20 Jul 2004 05:20
Date: Tue, 20 Jul 2004 05:20
60 lines
2800 bytes
2800 bytes
My application always has finished the thread and not a loop in the process.
As my example of my coding, I suspect the line number 1:, because I thought
when I set FreeOnTerminate to true, thread should be cleared and free up
memory but the pointer of object MyThread, need it to be cleared?
If it needs to be cleared, where the code that I have to put is.
In fact the line number 1: has been called a lot of times and I thought that
it should be OK if it is a thread with using FreeOnTerminate.
Main:
1: CMyThread *MyThread = new MyThread();
2: MyThread->Resume();
3: __fastcall CMyThread::CMyThread(bool CreateSuspended)
4: : TThread(CreateSuspended)
5: {
6: FreeOnTerminate = true;
7: }
8: void __fastcall CMyThread::Execute(void)
9: {
10: if (Terminated) return;
11: // Process here
12: //
13: FreeOnTerminate = true;
14: Terminate();
}
Sara T.
"JD" <nospam@nospam.com> wrote in message
news:40fc1022$1@newsgroups.borland.com...
>
> "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> wrote:
> > However, there is no leak in this case since FreeOnTerminate
> > is set to true. [...]
>
> I should have paid closer attention but the sample was so
> sparse that I ignored it, asking for more.
>
> ~ JD
>
"JD" <nospam@nospam.com> wrote in message
news:40fbf87b$1@newsgroups.borland.com...
> If you don't delete the thread when it's finished and allocate
> a new one - that's you're problem. And yes, that is a memory
> leak - a very big one at that.
However, there is no leak in this case since FreeOnTerminate is set to true.
The thread frees itself automatically when it finishes. Now, if the thread
never finishes, that would be a problem...
Gambit
Technical Details
Message-ID:
<40fcab00@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news-out.visi.com!petbe.visi.com!news.octanews.net!dimensional.com!pulsar.dimensional.com!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<40fb3d08@newsgroups.borland.com> <40fbf87b$1@newsgroups.borland.com> <40fbfd74$1@newsgroups.borland.com> <40fc1022$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,d35c53850c011fac X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Sara T." <sarana@infoquest.co.th> Newsgroups: borland.public.cppbuilder.nativeapi References: <40fb3d08@newsgroups.borland.com> <40fbf87b$1@newsgroups.borland.com> <40fbfd74$1@newsgroups.borland.com> <40fc1022$1@newsgroups.borland.com> Subject: Re: Thread and memory Date: Tue, 20 Jul 2004 12:20:00 +0700 Lines: 62 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 169.210.34.33 Message-ID: <40fcab00@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1090300672 169.210.34.33 (19 Jul 2004 22:17:52 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news-out.visi.com!petbe.visi.com!news.octanews.net!dimensional.com!pulsar.dimensional.com!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail