Heap allocated wasnt deleted.

I want to post a message to the main UI thread from a secondary thread, the message is a CString type, when I ran the EXE, the string posted from the threadPorc() could be shown on the main dialog, but in the Windows task manager, the "VM Size" kept incrmenting, it looked like that the heap allocated in the thread was not deleted at all.

Here is the code for the PostMessage() in the secondary thread.

static int WINAPI ThreadProc(LPVOID lpContext)
{
...
while(bRunning)
{
...
//Here post message to the main thread
CString * s = new CString("message from secondary thread ");
PostMessage(m_hWnd, WM_ADDSTRING, (WPARAM)s, 0);

}
...
return 0;
}

Message handler for the "WM_ADDSTRING"

LRESULT CMyDialog::OnAddString(WPARAM wp, LPARAM lp )
{
CString * temp=(CString *)wp;

m_ctrlList AddString(*temp);

delete temp;
return 0;
}

I can't work around it, Thanks for any help!
[1025 byte] By [forester] at [2007-11-20 11:57:39]
# 1 Re: Heap allocated wasnt deleted.
What you are doing is ok. You are allocating the CString and freeing it too. The VM may be increasing for other reasons, like the list control item addition.
kirants at 2007-11-11 4:01:51 >