Link to home
Start Free TrialLog in
Avatar of bigsteve87
bigsteve87

asked on

Will deleting a CWnd through it's own PostNcDestroy message cause a memory leak if it was allocated on the heap?

I have a splash screen window that is allocated on the heap and deleted in it's PostNcDestroy message handler.  Will this cause a memory leak?

The reason I'm asking is because a memory leak detection program pointed to the spot where I create a new Window on the heap with out deleting it before the function ended.  It may be wrong in this case.

Details below, if needed:

It is created like this:

BOOL CMainFrame::ShowSplashScreen()
{            
      pSplash=new CSplashScreen();      

      pSplash->Create(this,_T("My Splash"),1700,CSS_FADE | CSS_CENTERSCREEN | CSS_SHADOW);

      pSplash->Show();
}

And deleted like this:

void CSplashScreen::PostNcDestroy()
{
      CWnd::PostNcDestroy();
      delete this;
}


This is preferable because the splash screen is killed as soon as a timer runs out:

void CSplashScreen::OnTimer(UINT nIDEvent)
{
      KillTimer(0);
      ShowWindow(SW_HIDE);
      DestroyWindow();
}
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bigsteve87
bigsteve87

ASKER

Great answer, exactly what I needed.  Thanks!