Memory leak during termination of thread
-
Helllo everybody plz help me ... I started one thread in my application in mfc but on close of my view I got memory leak {367668} normal block at 0x021D82F0, 102 bytes long. Data: < C|& * > B8 AE 43 7C 26 00 00 00 2A 00 00 00 01 00 00 00 {367666} normal block at 0x121BA1E0, 102 bytes long. Data: < C| * > B8 AE 43 7C 1F 00 00 00 2A 00 00 00 01 00 00 00 {342539} normal block at 0x02219868, 118 bytes long. Data: <D : \ MyApp > 44 00 3A 00 5C 00 51 00 50 00 6C 00 75 00 73 00 {254649} normal block at 0x1216AA18, 70 bytes long. Data: < C| > B8 AE 43 7C 1A 00 00 00 1A 00 00 00 01 00 00 00 {188285} normal block at 0x02259E90, 70 bytes long. Data: < C| > B8 AE 43 7C 1A 00 00 00 1A 00 00 00 01 00 00 00 Object dump complete. This errors got. please help me In on close methode SetEvent(m_hKillThread); ::TerminateThread (m_Thread->m_hThread,1); WaitForSingleObject (m_Thread->m_hThread,INFINITE); m_Thread->Delete (); CloseHandle (m_hKillThread); Plz help me:confused::confused:
-
Helllo everybody plz help me ... I started one thread in my application in mfc but on close of my view I got memory leak {367668} normal block at 0x021D82F0, 102 bytes long. Data: < C|& * > B8 AE 43 7C 26 00 00 00 2A 00 00 00 01 00 00 00 {367666} normal block at 0x121BA1E0, 102 bytes long. Data: < C| * > B8 AE 43 7C 1F 00 00 00 2A 00 00 00 01 00 00 00 {342539} normal block at 0x02219868, 118 bytes long. Data: <D : \ MyApp > 44 00 3A 00 5C 00 51 00 50 00 6C 00 75 00 73 00 {254649} normal block at 0x1216AA18, 70 bytes long. Data: < C| > B8 AE 43 7C 1A 00 00 00 1A 00 00 00 01 00 00 00 {188285} normal block at 0x02259E90, 70 bytes long. Data: < C| > B8 AE 43 7C 1A 00 00 00 1A 00 00 00 01 00 00 00 Object dump complete. This errors got. please help me In on close methode SetEvent(m_hKillThread); ::TerminateThread (m_Thread->m_hThread,1); WaitForSingleObject (m_Thread->m_hThread,INFINITE); m_Thread->Delete (); CloseHandle (m_hKillThread); Plz help me:confused::confused:
shashankacharya wrote:
::TerminateThread (m_Thread->m_hThread,1);
Never use TerminateThread, this is a very bad approach. I suggest you read this article[^] from which you will learn a lot for threads. This is a long article but it's definitively worth reading it.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Helllo everybody plz help me ... I started one thread in my application in mfc but on close of my view I got memory leak {367668} normal block at 0x021D82F0, 102 bytes long. Data: < C|& * > B8 AE 43 7C 26 00 00 00 2A 00 00 00 01 00 00 00 {367666} normal block at 0x121BA1E0, 102 bytes long. Data: < C| * > B8 AE 43 7C 1F 00 00 00 2A 00 00 00 01 00 00 00 {342539} normal block at 0x02219868, 118 bytes long. Data: <D : \ MyApp > 44 00 3A 00 5C 00 51 00 50 00 6C 00 75 00 73 00 {254649} normal block at 0x1216AA18, 70 bytes long. Data: < C| > B8 AE 43 7C 1A 00 00 00 1A 00 00 00 01 00 00 00 {188285} normal block at 0x02259E90, 70 bytes long. Data: < C| > B8 AE 43 7C 1A 00 00 00 1A 00 00 00 01 00 00 00 Object dump complete. This errors got. please help me In on close methode SetEvent(m_hKillThread); ::TerminateThread (m_Thread->m_hThread,1); WaitForSingleObject (m_Thread->m_hThread,INFINITE); m_Thread->Delete (); CloseHandle (m_hKillThread); Plz help me:confused::confused:
First, do not use TerminateThread() to forcely terminate thread. The best way is let the thread terminate itself. If you want to terminate thread while thread is running, set a flag to notify the thread and let it self-terminate. Read the book "Multithreading Applications in Win32", a good book you need to read before you use multithread. Second, you need to check your code to see where you dynamic created variable but not delete it upon thread exit. You need to check this yourself, no other people can help you.
-
shashankacharya wrote:
::TerminateThread (m_Thread->m_hThread,1);
Never use TerminateThread, this is a very bad approach. I suggest you read this article[^] from which you will learn a lot for threads. This is a long article but it's definitively worth reading it.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++Thanx Cedric Before using terminatethread, I used same logic which given into link but at that time I got run time exception on delete Cwin thread.. is there having another way to remove memory leak.... Can vld find out memory leak which occures due to thread termination. Thank You For your reply...
-
First, do not use TerminateThread() to forcely terminate thread. The best way is let the thread terminate itself. If you want to terminate thread while thread is running, set a flag to notify the thread and let it self-terminate. Read the book "Multithreading Applications in Win32", a good book you need to read before you use multithread. Second, you need to check your code to see where you dynamic created variable but not delete it upon thread exit. You need to check this yourself, no other people can help you.
Thanx for your reply... I will read that book. And in my thread I just used local Variable, mydoc variable and my view variables...
-
Thanx for your reply... I will read that book. And in my thread I just used local Variable, mydoc variable and my view variables...
even if you use local variables you'll end up with memory leaks if the thread is not properly shutdown... good luck! :)
-
even if you use local variables you'll end up with memory leaks if the thread is not properly shutdown... good luck! :)
thanx albert