Hi,all
See there are code on a Timer callback:
void CThreadTestDlg::OnTimer(UINT nIDEvent)
{
static int nCount = 0;
if(!m_bThreadRun)
{
nCount++;
m_bThreadRun = TRUE;
pThread = (CMyThread*)AfxBeginThread(RUNTIME_CLASS(CMyThread),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
ASSERT(pThread!=NULL);
pThread->m_pBRun = &m_bThreadRun; //When this thread Exit , m_bThreadRun will be set to FALSE.
pThread->ResumeThread();
TRACE(“Current count %d\n”,nCount);
}
}
BOOL CMyThread::InitInstance()
{
// TODO: perform and per-thread initialization here
TRACE(“Thread initinstance()\n”);
PostQuitMessage(0);
return TRUE;
}
int CMyThread::ExitInstance()
{
// TODO: perform any per-thread cleanup here
TRACE(“Thread Exinitinstance()\n”);
*m_pBRun = FALSE;
return CWinThread::ExitInstance();
}
When I run there code more timers , the process use more memory.
Is this a memory leak ?
why?
Thanks in advance.
Crasher Guo
Hi Crasher,
It is not memory leak. Please look in the MSDN for creating the Class based thread.
Good Luck,
From: “Crasher Guo”
>Reply-To: “NT Developers Interest List”
>To: “NT Developers Interest List”
>Subject: [ntdev] memory leak to AfxBeginThread…
>Date: Tue, 27 May 2003 9:11:11 +0800
>
>Hi,all
>
>See there are code on a Timer callback:
>
>void CThreadTestDlg::OnTimer(UINT nIDEvent)
>{
> static int nCount = 0;
> if(!m_bThreadRun)
> {
> nCount++;
> m_bThreadRun = TRUE;
> pThread = (CMyThread*)AfxBeginThread(RUNTIME_CLASS(CMyThread),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
> ASSERT(pThread!=NULL);
> pThread->m_pBRun = &m_bThreadRun; //When this thread Exit , m_bThreadRun will be set to FALSE.
> pThread->ResumeThread();
>
> TRACE(“Current count %d\n”,nCount);
> }
>}
>
>BOOL CMyThread::InitInstance()
>{
> // TODO: perform and per-thread initialization here
>
> TRACE(“Thread initinstance()\n”);
>
> PostQuitMessage(0);
>
> return TRUE;
>}
>
>int CMyThread::ExitInstance()
>{
> // TODO: perform any per-thread cleanup here
>
> TRACE(“Thread Exinitinstance()\n”);
>
> *m_pBRun = FALSE;
>
> return CWinThread::ExitInstance();
>}
>
>
>When I run there code more timers , the process use more memory.
>Is this a memory leak ?
>why?
>
>
>
>Thanks in advance.
>Crasher Guo
>
>
>
>
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com
Himalayan holiday! Waiting to be won Find out more
Hi,yatindra vaishnav
Thanks for you reply.
> It is not memory leak. Please look in the MSDN for creating the Class based thread.
I don’t think so.
I have change AfxBeginThread to _beginThread ,change CMyThread to “void* MyThreadFunction(void* pParam)”, but I got the same result: more times thread start , end , more memory the process used.
My OS is Windows XP.
???
======== 2003-05-27 08:01:00 You wrote ========
Hi Crasher,
It is not memory leak. Please look in the MSDN for creating the Class based thread.
Good Luck,
>From: “Crasher Guo”
>Reply-To: “NT Developers Interest List”
>To: “NT Developers Interest List”
>Subject: [ntdev] memory leak to AfxBeginThread…
>Date: Tue, 27 May 2003 9:11:11 +0800
>
>Hi,all
>
>See there are code on a Timer callback:
>
>void CThreadTestDlg::OnTimer(UINT nIDEvent)
>{
> static int nCount = 0;
> if(!m_bThreadRun)
> {
> nCount++;
> m_bThreadRun = TRUE;
> pThread = (CMyThread*)AfxBeginThread(RUNTIME_CLASS(CMyThread),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
> ASSERT(pThread!=NULL);
> pThread->m_pBRun = &m_bThreadRun; //When this thread Exit , m_bThreadRun will be set to FALSE.
> pThread->ResumeThread();
>
> TRACE(“Current count %d\n”,nCount);
> }
>}
>
>BOOL CMyThread::InitInstance()
>{
> // TODO: perform and per-thread initialization here
>
> TRACE(“Thread initinstance()\n”);
>
> PostQuitMessage(0);
>
> return TRUE;
>}
>
>int CMyThread::ExitInstance()
>{
> // TODO: perform any per-thread cleanup here
>
> TRACE(“Thread Exinitinstance()\n”);
>
> *m_pBRun = FALSE;
>
> return CWinThread::ExitInstance();
>}
>
>
>When I run there code more times , the process use more memory.
>Is this a memory leak ?
>why?
>
>
>
>Thanks in advance.
>Crasher Guo
>
>
>
>
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com
Himalayan holiday! Waiting to be won Find out more —
You are currently subscribed to ntdev as: xxxxx@sinfors.com.cn
To unsubscribe send a blank email to xxxxx@lists.osr.com
= = = = = = = = = = = = = = = = = = = = = =
Crasher Guo
xxxxx@sinfors.com.cn
Hi Crasher,
Use CreateThread Win32 API…
Good Luck,
From: “Crasher Guo”
>Reply-To: “NT Developers Interest List”
>To: “NT Developers Interest List”
>Subject: [ntdev] Re: memory leak to AfxBeginThread…
>Date: Tue, 27 May 2003 17:5:6 +0800
>
>Hi,yatindra vaishnav
>
>Thanks for you reply.
>
> >> It is not memory leak. Please look in the MSDN for creating the Class based thread.
>I don’t think so.
>I have change AfxBeginThread to _beginThread ,change CMyThread to “void* MyThreadFunction(void* pParam)”, but I got the same result: more times thread start , end , more memory the process used.
>My OS is Windows XP.
>¡¡¡¡
>
>======== 2003-05-27 08:01:00 You wrote ========
>
>Hi Crasher,
> It is not memory leak. Please look in the MSDN for creating the Class based thread.
>
>Good Luck,
>
>
>
> >From: “Crasher Guo”
> >Reply-To: “NT Developers Interest List”
> >To: “NT Developers Interest List”
> >Subject: [ntdev] memory leak to AfxBeginThread…
> >Date: Tue, 27 May 2003 9:11:11 +0800
> >
> >Hi,all
> >
> >See there are code on a Timer callback:
> >
> >void CThreadTestDlg::OnTimer(UINT nIDEvent)
> >{
> > static int nCount = 0;
> > if(!m_bThreadRun)
> > {
> > nCount++;
> > m_bThreadRun = TRUE;
> > pThread = (CMyThread*)AfxBeginThread(RUNTIME_CLASS(CMyThread),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
> > ASSERT(pThread!=NULL);
> > pThread->m_pBRun = &m_bThreadRun; //When this thread Exit , m_bThreadRun will be set to FALSE.
> > pThread->ResumeThread();
> >
> > TRACE(“Current count %d\n”,nCount);
> > }
> >}
> >
> >BOOL CMyThread::InitInstance()
> >{
> > // TODO: perform and per-thread initialization here
> >
> > TRACE(“Thread initinstance()\n”);
> >
> > PostQuitMessage(0);
> >
> > return TRUE;
> >}
> >
> >int CMyThread::ExitInstance()
> >{
> > // TODO: perform any per-thread cleanup here
> >
> > TRACE(“Thread Exinitinstance()\n”);
> >
> > *m_pBRun = FALSE;
> >
> > return CWinThread::ExitInstance();
> >}
> >
> >
> >When I run there code more times , the process use more memory.
> >Is this a memory leak ?
> >why?
> >
> >
> >
> >Thanks in advance.
> >Crasher Guo
> >
> >
> >
> >
> >
> >
> >—
> >You are currently subscribed to ntdev as: xxxxx@hotmail.com
> >To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>Himalayan holiday! Waiting to be won Find out more —
>You are currently subscribed to ntdev as: xxxxx@sinfors.com.cn
>To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>= = = = = = = = = = = = = = = = = = = = = =
>Crasher Guo
>xxxxx@sinfors.com.cn
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com
Race along with NK. The fastest Indian Feel the thrill!
Are you deleting the thread object.
Try setting m_bAutoDelete flag of pThread to TRUE before calling ResumeThread().
regards,
sujith
----- Original Message -----
From: Crasher Guo
To: NT Developers Interest List
Sent: Tuesday, May 27, 2003 12:00 AM
Subject: [ntdev] Re: memory leak to AfxBeginThread…
Hi,yatindra vaishnav
Thanks for you reply.
> It is not memory leak. Please look in the MSDN for creating the Class based thread.
I don’t think so.
I have change AfxBeginThread to _beginThread ,change CMyThread to “void* MyThreadFunction(void* pParam)”, but I got the same result: more times thread start , end , more memory the process used.
My OS is Windows XP.
???
======== 2003-05-27 08:01:00 You wrote ========
Hi Crasher,
It is not memory leak. Please look in the MSDN for creating the Class based thread.
Good Luck,
>From: “Crasher Guo”
>Reply-To: “NT Developers Interest List”
>To: “NT Developers Interest List”
>Subject: [ntdev] memory leak to AfxBeginThread…
>Date: Tue, 27 May 2003 9:11:11 +0800
>
>Hi,all
>
>See there are code on a Timer callback:
>
>void CThreadTestDlg::OnTimer(UINT nIDEvent)
>{
> static int nCount = 0;
> if(!m_bThreadRun)
> {
> nCount++;
> m_bThreadRun = TRUE;
> pThread = (CMyThread*)AfxBeginThread(RUNTIME_CLASS(CMyThread),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
> ASSERT(pThread!=NULL);
> pThread->m_pBRun = &m_bThreadRun; //When this thread Exit , m_bThreadRun will be set to FALSE.
> pThread->ResumeThread();
>
> TRACE(“Current count %d\n”,nCount);
> }
>}
>
>BOOL CMyThread::InitInstance()
>{
> // TODO: perform and per-thread initialization here
>
> TRACE(“Thread initinstance()\n”);
>
> PostQuitMessage(0);
>
> return TRUE;
>}
>
>int CMyThread::ExitInstance()
>{
> // TODO: perform any per-thread cleanup here
>
> TRACE(“Thread Exinitinstance()\n”);
>
> *m_pBRun = FALSE;
>
> return CWinThread::ExitInstance();
>}
>
>
>When I run there code more times , the process use more memory.
>Is this a memory leak ?
>why?
>
>
>
>Thanks in advance.
>Crasher Guo
>
>
>
>
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com
----------------------------------------------------------------------
Himalayan holiday! Waiting to be won Find out more —
You are currently subscribed to ntdev as: xxxxx@sinfors.com.cn
To unsubscribe send a blank email to xxxxx@lists.osr.com
= = = = = = = = = = = = = = = = = = = = = =
Crasher Guo
xxxxx@sinfors.com.cn
—
You are currently subscribed to ntdev as: xxxxx@tataelxsi.co.in
To unsubscribe send a blank email to xxxxx@lists.osr.com
Hi,Sujith S
Thanks for you help.
I have set m_bAutoDelete flag to TRUE.
======= 2003-05-27 15:39:00 You wrote=======
Are you deleting the thread object.
Try setting m_bAutoDelete flag of pThread to TRUE before calling ResumeThread().
regards,
sujith
----- Original Message -----
From: Crasher Guo
To: NT Developers Interest List
Sent: Tuesday, May 27, 2003 12:00 AM
Subject: [ntdev] Re: memory leak to AfxBeginThread…
Hi,yatindra vaishnav
Thanks for you reply.
>> It is not memory leak. Please look in the MSDN for creating the Class based thread.
I don’t think so.
I have change AfxBeginThread to _beginThread ,change CMyThread to “void* MyThreadFunction(void* pParam)”, but I got the same result: more times thread start , end , more memory the process used.
My OS is Windows XP.
???
======== 2003-05-27 08:01:00 You wrote ========
Hi Crasher,
It is not memory leak. Please look in the MSDN for creating the Class based thread.
Good Luck,
>
>
>
> >From: “Crasher Guo”
> >Reply-To: “NT Developers Interest List”
> >To: “NT Developers Interest List”
> >Subject: [ntdev] memory leak to AfxBeginThread…
> >Date: Tue, 27 May 2003 9:11:11 +0800
> >
> >Hi,all
> >
> >See there are code on a Timer callback:
> >
> >void CThreadTestDlg::OnTimer(UINT nIDEvent)
> >{
> > static int nCount = 0;
> > if(!m_bThreadRun)
> > {
> > nCount++;
> > m_bThreadRun = TRUE;
> > pThread = (CMyThread*)AfxBeginThread(RUNTIME_CLASS(CMyThread),THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED);
> > ASSERT(pThread!=NULL);
> > pThread->m_pBRun = &m_bThreadRun; //When this thread Exit , m_bThreadRun will be set to FALSE.
> > pThread->ResumeThread();
> >
> > TRACE(“Current count d\n”,nCount);
> > }
> >}
> >
> >BOOL CMyThread::InitInstance()
> >{
> > // TODO: perform and per-thread initialization here
> >
> > TRACE(“Thread initinstance()\n”);
> >
> > PostQuitMessage(0);
> >
> > return TRUE;
> >}
> >
> >int CMyThread::ExitInstance()
> >{
> > // TODO: perform any per-thread cleanup here
> >
> > TRACE(“Thread Exinitinstance()\n”);
> >
> > *m_pBRun = FALSE;
> >
> > return CWinThread::ExitInstance();
> >}
> >
> >
> >When I run there code more times , the process use more memory.
> >Is this a memory leak ?
> >why?
> >
> >
> >
> >Thanks in advance.
> >Crasher Guo
> >
> >
> >
> >
> >
> >
> >—
> >You are currently subscribed to ntdev as: xxxxx@hotmail.com
> >To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>----------------------------------------------------------------------
> Himalayan holiday! Waiting to be won Find out more —
> You are currently subscribed to ntdev as: xxxxx@sinfors.com.cn
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
> = = = = = = = = = = = = = = = = = = = = = =
>
> Crasher Guo
> xxxxx@sinfors.com.cn
> —
> You are currently subscribed to ntdev as: xxxxx@tataelxsi.co.in
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>—
>You are currently subscribed to ntdev as: xxxxx@sinfors.com.cn
>To unsubscribe send a blank email to xxxxx@lists.osr.com
= = = = = = = = = = = = = = = = = = = =
Crasher Guo
xxxxx@sinfors.com.cn
2003-05-27
Hi,yatindra vaishnav
I’ve tried it with CreateThread Win32 API , and got the same result.
======= 2003-05-27 10:01:00 You wrote=======
= = = = = = = = = = = = = = = = = = = =
Crasher Guo
xxxxx@sinfors.com.cn
2003-05-27
Hi Crasher,
I dont think that because, u r indirectly teling that the Windows Memory management is not perfact.
Good Luck,
From: “Crasher Guo”
>Reply-To: “NT Developers Interest List”
>To: “NT Developers Interest List”
>Subject: [ntdev] Re: memory leak to AfxBeginThread…
>Date: Tue, 27 May 2003 18:41:57 +0800
>
>Hi,yatindra vaishnav
>
>I’ve tried it with CreateThread Win32 API , and got the same result.
>
>======= 2003-05-27 10:01:00 You wrote=======
>
>
>
>= = = = = = = = = = = = = = = = = = = =
>
>
>Crasher Guo
>xxxxx@sinfors.com.cn
>2003-05-27
>
>
>
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com
Want free fuel? Get IOC Citibank card Drive your dreams!
Hi,yatindra vaishnav??
Could you try this by youselft? I’ve tried many times and long time.
???
======== 2003-05-27 12:56:00 you wrote ========
Hi Crasher,
I dont think that because, u r indirectly teling that the Windows Memory management is not perfact.
Good Luck,
>From: “Crasher Guo”
>Reply-To: “NT Developers Interest List”
>To: “NT Developers Interest List”
>Subject: [ntdev] Re: memory leak to AfxBeginThread…
>Date: Tue, 27 May 2003 18:41:57 +0800
>
>Hi,yatindra vaishnav
>
>I’ve tried it with CreateThread Win32 API , and got the same result.
>
>======= 2003-05-27 10:01:00 You wrote=======
>
>
>
>= = = = = = = = = = = = = = = = = = = =
>
>
>Crasher Guo
>xxxxx@sinfors.com.cn
>2003-05-27
>
>
>
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com
Want free fuel? Get IOC Citibank card Drive your dreams! —
You are currently subscribed to ntdev as: xxxxx@sinfors.com.cn
To unsubscribe send a blank email to xxxxx@lists.osr.com
= = = = = = = = = = = = = = = = = = = = = =
Crasher Guo
xxxxx@sinfors.com.cn
Very simple. It works just as expected. Memory increases when new threads
are created and when they exit, memory returns to the amount that was
reserved before. I went up to 30 simultaneous threads.
Here is the relevant code, please look for memory leaks in your own app.
Mat
//-------
void CThreadmfcDlg::OnButton1()
{
AfxBeginThread(ThreadProc,this);
}
UINT CThreadmfcDlg::ThreadProc(PVOID context)
{
Sleep(5000);
return 0;
}
-----Original Message-----
From: Crasher Guo [mailto:xxxxx@sinfors.com.cn]
Sent: Monday, May 26, 2003 2:00 PM
To: NT Developers Interest List
Subject: [ntdev] Re: memory leak to AfxBeginThread…
Hi,yatindra vaishnav,
Could you try this by youselft? I’ve tried many times and long time.
======== 2003-05-27 12:56:00 you wrote ========
Hi Crasher,
I dont think that because, u r indirectly teling that the
Windows Memory management is not perfact.
Good Luck,
>From: “Crasher Guo”
>Reply-To: “NT Developers Interest List”
>To: “NT Developers Interest List”
>Subject: [ntdev] Re: memory leak to AfxBeginThread…
>Date: Tue, 27 May 2003 18:41:57 +0800
>
>Hi,yatindra vaishnav
>
>I’ve tried it with CreateThread Win32 API , and got the same result.
>
>======= 2003-05-27 10:01:00 You wrote=======
>
>
>
>= = = = = = = = = = = = = = = = = = = =
>
>
>Crasher Guo
>xxxxx@sinfors.com.cn
>2003-05-27
>
>
>
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com
Want free fuel? Get IOC Citibank card Drive your dreams! —
You are currently subscribed to ntdev as: xxxxx@sinfors.com.cn
To unsubscribe send a blank email to xxxxx@lists.osr.com
= = = = = = = = = = = = = = = = = = = = = =
Crasher Guo
xxxxx@sinfors.com.cn
—
You are currently subscribed to ntdev as: xxxxx@guillemot.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
Hi Crasher,
I tried that. and gettin the result that it cleans the memory as u do that.
Good Luck,
From: “Crasher Guo”
>Reply-To: “NT Developers Interest List”
>To: “NT Developers Interest List”
>Subject: [ntdev] Re: memory leak to AfxBeginThread…
>Date: Tue, 27 May 2003 21:47:1 +0800
>
>Hi,yatindra vaishnav£¬
>Could you try this by youselft? I’ve tried many times and long time.
>¡¡¡¡
>
>======== 2003-05-27 12:56:00 you wrote ========
>
>Hi Crasher,
> I dont think that because, u r indirectly teling that the Windows Memory management is not perfact.
>Good Luck,
>
>
>
> >From: “Crasher Guo”
> >Reply-To: “NT Developers Interest List”
> >To: “NT Developers Interest List”
> >Subject: [ntdev] Re: memory leak to AfxBeginThread…
> >Date: Tue, 27 May 2003 18:41:57 +0800
> >
> >Hi,yatindra vaishnav
> >
> >I’ve tried it with CreateThread Win32 API , and got the same result.
> >
> >======= 2003-05-27 10:01:00 You wrote=======
> >
> >
> >
> >= = = = = = = = = = = = = = = = = = = =
> >
> >
> >Crasher Guo
> >xxxxx@sinfors.com.cn
> >2003-05-27
> >
> >
> >
> >
> >
> >—
> >You are currently subscribed to ntdev as: xxxxx@hotmail.com
> >To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
>Want free fuel? Get IOC Citibank card Drive your dreams! —
>You are currently subscribed to ntdev as: xxxxx@sinfors.com.cn
>To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>= = = = = = = = = = = = = = = = = = = = = =
>Crasher Guo
>xxxxx@sinfors.com.cn
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@hotmail.com
>To unsubscribe send a blank email to xxxxx@lists.osr.com
Staying fit. It’s about being happy! Check out the new mantra
Dear Crasher,
The m_bAutoDelete member flag is set to TRUE by default, so you
shouldn’t need to set it. It’s not surprising that the OS may allocate
some memory as more threads are created and not free it later. The OS
may dynamically size internal buffers and not necessarily free them.
But you can easily check to see if it’s really a memory leak or not:
- Create some threads, say 10.
- Check the amount of memory.
- Terminate all threads and destroy all thread objects.
- Create the same number of threads again, say 10.
- Check the memory again. If the memory is the same as in #2, there is
no leak. If the memory is less than in #2, there is a leak.
Chuck
----- Original Message -----
From: “Crasher Guo”
To: “NT Developers Interest List”
Sent: Tuesday, May 27, 2003 8:11 AM
Subject: [ntdev] memory leak to AfxBeginThread…
> Hi,all
>
> See there are code on a Timer callback:
>
> void CThreadTestDlg::OnTimer(UINT nIDEvent)
> {
> static int nCount = 0;
> if(!m_bThreadRun)
> {
> nCount++;
> m_bThreadRun = TRUE;
> pThread =
(CMyThread*)AfxBeginThread(RUNTIME_CLASS(CMyThread),THREAD_PRIORITY_NORM
AL,0,CREATE_SUSPENDED);
> ASSERT(pThread!=NULL);
> pThread->m_pBRun = &m_bThreadRun; //When this thread Exit ,
m_bThreadRun will be set to FALSE.
> pThread->ResumeThread();
>
> TRACE(“Current count %d\n”,nCount);
> }
> }
>
> BOOL CMyThread::InitInstance()
> {
> // TODO: perform and per-thread initialization here
>
> TRACE(“Thread initinstance()\n”);
>
> PostQuitMessage(0);
>
> return TRUE;
> }
>
> int CMyThread::ExitInstance()
> {
> // TODO: perform any per-thread cleanup here
>
> TRACE(“Thread Exinitinstance()\n”);
>
> *m_pBRun = FALSE;
>
> return CWinThread::ExitInstance();
> }
>
>
> When I run there code more timers , the process use more memory.
> Is this a memory leak ?
> why?
>
>
>
> Thanks in advance.
> Crasher Guo
Hi,Chuck Batson
Thanks for you reply. Now I see.
Thanks everybody,my program now run perfectly.
======= 2003-05-28 12:05:00 You wrote=======
Dear Crasher,
The m_bAutoDelete member flag is set to TRUE by default, so you
shouldn’t need to set it. It’s not surprising that the OS may allocate
some memory as more threads are created and not free it later. The OS
may dynamically size internal buffers and not necessarily free them.
But you can easily check to see if it’s really a memory leak or not:
- Create some threads, say 10.
- Check the amount of memory.
- Terminate all threads and destroy all thread objects.
- Create the same number of threads again, say 10.
- Check the memory again. If the memory is the same as in #2, there is
no leak. If the memory is less than in #2, there is a leak.
Chuck
----- Original Message -----
From: “Crasher Guo”
>To: “NT Developers Interest List”
>Sent: Tuesday, May 27, 2003 8:11 AM
>Subject: [ntdev] memory leak to AfxBeginThread…
>
>
>> Hi,all
>>
>> See there are code on a Timer callback:
>>
>> void CThreadTestDlg::OnTimer(UINT nIDEvent)
>> {
>> static int nCount = 0;
>> if(!m_bThreadRun)
>> {
>> nCount++;
>> m_bThreadRun = TRUE;
>> pThread =
>(CMyThread*)AfxBeginThread(RUNTIME_CLASS(CMyThread),THREAD_PRIORITY_NORM
>AL,0,CREATE_SUSPENDED);
>> ASSERT(pThread!=NULL);
>> pThread->m_pBRun = &m_bThreadRun; //When this thread Exit ,
>m_bThreadRun will be set to FALSE.
>> pThread->ResumeThread();
>>
>> TRACE(“Current count d\n”,nCount);
>> }
>> }
>>
>> BOOL CMyThread::InitInstance()
>> {
>> // TODO: perform and per-thread initialization here
>>
>> TRACE(“Thread initinstance()\n”);
>>
>> PostQuitMessage(0);
>>
>> return TRUE;
>> }
>>
>> int CMyThread::ExitInstance()
>> {
>> // TODO: perform any per-thread cleanup here
>>
>> TRACE(“Thread Exinitinstance()\n”);
>>
>> *m_pBRun = FALSE;
>>
>> return CWinThread::ExitInstance();
>> }
>>
>>
>> When I run there code more timers , the process use more memory.
>> Is this a memory leak ?
>> why?
>>
>>
>>
>> Thanks in advance.
>> Crasher Guo
>
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@sinfors.com.cn
>To unsubscribe send a blank email to xxxxx@lists.osr.com
= = = = = = = = = = = = = = = = = = = =
Crasher Guo
xxxxx@sinfors.com.cn
2003-05-28
Chuck,
And what is the explaination for that strange behaviour ? Is it becoz of the
assumption that previously allocated and leaked memory will be reused ??
Amit
“Chuck Batson” wrote in message news:xxxxx@ntdev…
>
> Dear Crasher,
>
> The m_bAutoDelete member flag is set to TRUE by default, so you
> shouldn’t need to set it. It’s not surprising that the OS may allocate
> some memory as more threads are created and not free it later. The OS
> may dynamically size internal buffers and not necessarily free them.
> But you can easily check to see if it’s really a memory leak or not:
>
> 1. Create some threads, say 10.
> 2. Check the amount of memory.
> 3. Terminate all threads and destroy all thread objects.
> 4. Create the same number of threads again, say 10.
> 5. Check the memory again. If the memory is the same as in #2, there is
> no leak. If the memory is less than in #2, there is a leak.
>
> Chuck
>
> ----- Original Message -----
> From: “Crasher Guo”
> To: “NT Developers Interest List”
> Sent: Tuesday, May 27, 2003 8:11 AM
> Subject: [ntdev] memory leak to AfxBeginThread…
>
>
> > Hi,all
> >
> > See there are code on a Timer callback:
> >
> > void CThreadTestDlg::OnTimer(UINT nIDEvent)
> > {
> > static int nCount = 0;
> > if(!m_bThreadRun)
> > {
> > nCount++;
> > m_bThreadRun = TRUE;
> > pThread =
> (CMyThread*)AfxBeginThread(RUNTIME_CLASS(CMyThread),THREAD_PRIORITY_NORM
> AL,0,CREATE_SUSPENDED);
> > ASSERT(pThread!=NULL);
> > pThread->m_pBRun = &m_bThreadRun; file://When this thread Exit ,
> m_bThreadRun will be set to FALSE.
> > pThread->ResumeThread();
> >
> > TRACE(“Current count %d\n”,nCount);
> > }
> > }
> >
> > BOOL CMyThread::InitInstance()
> > {
> > // TODO: perform and per-thread initialization here
> >
> > TRACE(“Thread initinstance()\n”);
> >
> > PostQuitMessage(0);
> >
> > return TRUE;
> > }
> >
> > int CMyThread::ExitInstance()
> > {
> > // TODO: perform any per-thread cleanup here
> >
> > TRACE(“Thread Exinitinstance()\n”);
> >
> > *m_pBRun = FALSE;
> >
> > return CWinThread::ExitInstance();
> > }
> >
> >
> > When I run there code more timers , the process use more memory.
> > Is this a memory leak ?
> > why?
> >
> >
> >
> > Thanks in advance.
> > Crasher Guo
>
>
>
>
Dear Amit,
For the exact answer, you’d have to ask the author of the software in
question. =^) However, I presume the reason is something along the
lines you reckon. I’ve seen this sort of behavior in various Windows
APIs/subsystems. There could be a performance reason, if there’s a
high overhead for setting up the particular subsystem’s internal
buffers, but more likely it’s just easier to leave the memory allocated.
Leaving a bunch of virtual memory allocated doesn’t really hurt
anything – unused memory will just get paged out and not thought of
again until it’s used. Though your available virtual address space will
be reduced, and the (paged-out) memory may consume space in the page
file.
Chuck
“Amit Manocha” wrote:
> Chuck,
>
> And what is the explaination for that strange behaviour ? Is it becoz
of the
> assumption that previously allocated and leaked memory will be reused
??
>
> Amit
> “Chuck Batson” wrote in message news:xxxxx@ntdev…
> >
> > Dear Crasher,
> >
> > The m_bAutoDelete member flag is set to TRUE by default, so you
> > shouldn’t need to set it. It’s not surprising that the OS may
allocate
> > some memory as more threads are created and not free it later. The
OS
> > may dynamically size internal buffers and not necessarily free them.
> > But you can easily check to see if it’s really a memory leak or not:
> >
> > 1. Create some threads, say 10.
> > 2. Check the amount of memory.
> > 3. Terminate all threads and destroy all thread objects.
> > 4. Create the same number of threads again, say 10.
> > 5. Check the memory again. If the memory is the same as in #2,
there is
> > no leak. If the memory is less than in #2, there is a leak.
> >
> > Chuck
> >
> > ----- Original Message -----
> > From: “Crasher Guo”
> > To: “NT Developers Interest List”
> > Sent: Tuesday, May 27, 2003 8:11 AM
> > Subject: [ntdev] memory leak to AfxBeginThread…
> >
> >
> > > Hi,all
> > >
> > > See there are code on a Timer callback:
> > >
> > > void CThreadTestDlg::OnTimer(UINT nIDEvent)
> > > {
> > > static int nCount = 0;
> > > if(!m_bThreadRun)
> > > {
> > > nCount++;
> > > m_bThreadRun = TRUE;
> > > pThread =
> >
(CMyThread*)AfxBeginThread(RUNTIME_CLASS(CMyThread),THREAD_PRIORITY_NORM
> > AL,0,CREATE_SUSPENDED);
> > > ASSERT(pThread!=NULL);
> > > pThread->m_pBRun = &m_bThreadRun; file://When this thread Exit ,
> > m_bThreadRun will be set to FALSE.
> > > pThread->ResumeThread();
> > >
> > > TRACE(“Current count %d\n”,nCount);
> > > }
> > > }
> > >
> > > BOOL CMyThread::InitInstance()
> > > {
> > > // TODO: perform and per-thread initialization here
> > >
> > > TRACE(“Thread initinstance()\n”);
> > >
> > > PostQuitMessage(0);
> > >
> > > return TRUE;
> > > }
> > >
> > > int CMyThread::ExitInstance()
> > > {
> > > // TODO: perform any per-thread cleanup here
> > >
> > > TRACE(“Thread Exinitinstance()\n”);
> > >
> > > *m_pBRun = FALSE;
> > >
> > > return CWinThread::ExitInstance();
> > > }
> > >
> > >
> > > When I run there code more timers , the process use more memory.
> > > Is this a memory leak ?
> > > why?
> > >
> > >
> > >
> > > Thanks in advance.
> > > Crasher Guo