Re: Memory leak with CAsyncSocket::Create
On Tue, 10 Jul 2007 21:19:23 -0700, "Michael K. O'Neill"
<mikeathon2000@nospam.hotmail.com> wrote:
That *is* very interesting. When we looked at this two years ago, we
noticed that the leak disappeared when creating a child window, but we
didn't look any furhter, and we didn't think to try a top-level window. We
eventually concluded that the problem was related to the creation of the
socket's hidden window, but that it didn't show itself unless XP visual
styles (themes) was enabled, i.e., inclusion of a manifest with the program.
With a top-level window, does it make a difference as to whether themes is
or is not enabled? Was our answer back then completely off-base?
I haven't tested the theme aspect, but assuming it's correct, there's
clearly a bad interaction between top-level windows and themes that has
nothing to do with sockets. The CreateEx call is a simplified version of
what CAsyncSocket::AttachHandle does. You can easily test this. Just create
a default MFC SDI app and put the loop in OnAppAbout; at least, that's my
favorite way to test stuff like this. So I had:
void Cdef_sockApp::OnAppAbout()
{
for (int i=0; i<1000; ++i)
{
#if 0
CAsyncSocket *pAS = new CAsyncSocket;
pAS->Create();
pAS->Close();
delete pAS;
#else
CWnd* p = new CWnd;
#if 1
p->CreateEx(0, AfxRegisterWndClass(0), 0,
WS_OVERLAPPED, CRect(), 0, 0);
#else
p->Create(AfxRegisterWndClass(0), 0,
WS_CHILD, CRect(), AfxGetMainWnd(), 0);
#endif
p->DestroyWindow();
delete p;
#endif
}
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
The next step would be to reduce this to the Windows API level and do it
all in terms of raw HWNDs. The window and window class styles might also be
a factor.
--
Doug Harrison
Visual C++ MVP