On Feb 9, 5:25 pm, Joseph M. Newcomer <newco...@flounder.com> wrote:
If you are leaking from a "CFrameWnd" object, it is unlikely that it
is a CWinThread
object. Could you show the message?
Normally, when you create a CWinThread-derived thread, the
m_bAutoDelete flag is TRUE, and
therefore the CWinThread object will be automatically deleted when the
thread terminates.
This would be verified by the fact that an attempt to delete it a
second time results in a
catastrophic failure. So it is unlikely that it is your CmyUIthread
object. But make
sure the destructors for that object delete anything it had allocated;
for example, if it
had a CWhatever* pointer in it, its destructor had better delete that
object (unless
someone else has responsibility for deleting it)
joe
On Sat, 9 Feb 2008 07:21:14 -0800 (PST), ole.tetzsch...@gmail.com
wrote:
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
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm
Hi Joseph
Thanks for you quick reply :)
The messages is:
The thread 'Win32 Thread' (0x6c0) has exited with code 0 (0x0).
Detected memory leaks!
Dumping objects ->
f:\sp\vctools\vc7libs\ship\atlmfc\src\mfc\strcore.cpp(141) : {105}
normal block at 0x003A74D0, 34 bytes long.
Data: <, ?x > 2C 08 3F 78 11 00 00 00 11 00 00 00 01 00 00
00
{104} client block at 0x003A98B0, subtype c0, 212 bytes long.
a CFrameWnd object at $003A98B0, 212 bytes long
Seems pretty obvious what hasn't been cleaned up. What you create you
are reponsible for removing.
You have to close or Destroy your CFrameWnd. It would be easier to
derive a new class from CFrameWnd so you can handle messages for it.
Object dump complete.
The program '[3232] myThreadTest.exe: Native' has exited with code 2
(0x2).
This is a fresh wizard-generated dialog project where I add the
CWinThread derived class also by the wizard. The only code I added to
CmyUIthread is in the InitInstance... and changed the destructor and
constructor to public (so I could use the "new" to generate the object
in my dialog-test-app).
What is it I need to clean-up ???
With kind regards... Ole