mfc >> CWinThread and memory leak

by Aling » Fri, 28 Nov 2003 14:52:41 GMT

In one program, I created one secondary thread which derived from
CWinThread, and m_bAutoDelete of this secondary thread was setted to FALSE.

The instance of this secondary thread was declared as one global variable,
and it also used some other global variables to do some processing. And in
destructor of those global variables class, all clean up work were done.

The problem was that , before program ended I used ::PostThreadMessage(...)
to post WM_QUIT to the secondary thread, and also it received this message
and ended, but the global variables always bring up memory leak.

What's wrong with the secondary thread?

Any help are appreciated, Thanks.

BR

aling


--





mfc >> CWinThread and memory leak

by Mihajlo Cvetanovic » Fri, 28 Nov 2003 19:43:33 GMT





Try to move cleanup code of your windows (if there is any) from
WM_CLOSE to WM_DESTROY.




mfc >> CWinThread and memory leak

by xmontyx » Sat, 29 Nov 2003 18:15:34 GMT

are you waiting some where for the child thread to stop executing ?
or post a message and Die !





Similar Threads

1. CWinThread and memory leak

In one program, I created one secondary thread which derived from
CWinThread, and m_bAutoDelete of this secondary thread was setted to FALSE.

The instance of this secondary thread was declared as one global variable,
and it also used some other global variables to do some processing. And in
destructor of those global variables class,  all clean up work were done.

The problem was that ,  before program ended I used ::PostQuitMessage(...)
to post WM_QUIT to the secondary thread,  and also it received this message
and ended,  but the global variables always bring up memory leak.

What's wrong with the secondary thread?

Any help are appreciated, Thanks.

BR

aling

-- 



2. CWinThread and Memory Leaks.

3. CWinThread, CFrameWnd and memory leak???

Hi

I guess it's just me being stupid, but I been googling and trying for
hours now and can't solve this problem myself.

The Problem is I have created a class (CmyUIthread) derived from
CWinThread, but when my test-app exit the compiler reports a memory
leak from a CFrameWnd object.

My test-app is just a dialog-app with 2 buttons. The first button just
create and starts the ui-thread:

	m_p_thread = new CmyUIthread;
	m_p_thread->CreateThread();

And the tread starts perfect :)

The second button stops the thread:

	m_p_thread->PostThreadMessage( WM_QUIT,0,0);

And the thread stops :)

But when i quit my dlg-test-app the compiler reports the memory
leak???

I tried adding a third button that:

	delete m_p_thread;

but this results in access violations.

CmyUIthread looks like this:

CmyUIthread::CmyUIthread()
{
}

CmyUIthread::~CmyUIthread()
{
}

BOOL CmyUIthread::InitInstance()
{
	// TODO:  perform and per-thread initialization here
	CFrameWnd *wnd = new CFrameWnd;
	wnd->Create( NULL, "myUIthread Window");
	wnd->ShowWindow( SW_SHOW);
	wnd->UpdateWindow();
	m_pMainWnd = wnd;

	return TRUE;
}

int CmyUIthread::ExitInstance()
{
	// TODO:  perform any per-thread cleanup here
	return CWinThread::ExitInstance();
}

BEGIN_MESSAGE_MAP(CmyUIthread, CWinThread)
END_MESSAGE_MAP()


What is wrong??? do I miss some cleanup???


With kind regards.. Ole

4. Memory leak CWinthread object

5. How to detect memory leak and detect who causes a memory leak

6. Memory leak even after deleting memory pointers from vector

7. Memory leak indiaction in .NET app with C++ interop dll's

We are working on a .NET program which uses several dlls, both pure c# DLL'S 
and dll's written in C++ interop and in addition 3 party SW from several 
vendors.
The managed C++ dll are wrappers for interfacing native C++ code which we 
have link in as static libraries.
When we exit the program we get very many indications on memroy leaks dumped 
by the function _CrtDumpMemoryLeaks. After debugging a bit, the problem is 
that at the time _CrtDumpMemoryLeaks is called (destructor of afxState class 
inside MFC 8.0 dll), several of the managed C++ dll's are not unloaded, thus 
their static/global C++ objects destructors have not been called. 
Since we use system multithreaded dll's they share the same heap. 
Is there a way to be sure that _CrtDumpMemoryLeaks are called after all 
destructors have been called for all dll's? On stop the _CrtDumpMemoryLeaks 
called from the destructor of afxState?


8. Memory Leak in C++ Excel RTD (same as in VCRTDServer)