Is the StarrtHerePage:: htmlWindow being leaked because it is never Destroy()ed?
In startherepage.cpp line 66 the htmlWindow is allocated:
StartHerePage::StartHerePage(wxEvtHandler* owner, wxWindow* parent)
: EditorBase(parent, g_StartHereTitle),
m_pOwner(owner)
{
//ctor
wxBoxSizer* bs = new wxBoxSizer(wxVERTICAL);
wxString resPath = ConfigManager::ReadDataPath();
m_pWin = new MyHtmlWin(this, idWin, wxPoint(0,0), GetSize());
But the htmlWindow is *not* destroyed because the code is commented out:
startherepage.cpp line 133
startherepage.cpp 133
StartHerePage::~StartHerePage()
{
//dtor
//m_pWin->Destroy();
}
The StartHerePage itself *is* destroyed at:
main.cpp lines 1760 & 1772
void MainFrame::ShowHideStartPage(bool forceHasProject)
{
if (Manager::IsBatchBuild())
return;
// we use the 'forceHasProject' param because when a project is opened
// the EVT_PROJECT_OPEN event is fired *before* ProjectManager::GetProjects()
// and ProjectManager::GetActiveProject() are updated...
if(m_InitiatedShutdown)
{
EditorBase* sh = Manager::Get()->GetEditorManager()->GetEditor(g_StartHereTitle);
if (sh)
sh->Destroy();
return;
}
bool show = !forceHasProject &&
Manager::Get()->GetProjectManager()->GetProjects()->GetCount() == 0 &&
Manager::Get()->GetConfigManager(_T("app"))->ReadBool(_T("/environment/start_here_page"), true);
EditorBase* sh = Manager::Get()->GetEditorManager()->GetEditor(g_StartHereTitle);
if (show && !sh)
sh = new StartHerePage(this, Manager::Get()->GetEditorManager()->GetNotebook());
else if (!show && sh)
sh->Destroy();
}
Any other referenced to m_pWin are:
src\startherepage.cpp|66|m_pWin = new MyHtmlWin(this, idWin, wxPoint(0,0), GetSize());|
src\startherepage.cpp|79|m_pWin->SetFonts(wxEmptyString, wxEmptyString, &sizes[0]);|
src\startherepage.cpp|82|m_pWin->LoadPage(resPath + _T("/start_here.zip#zip:start_here.html"));|
src\startherepage.cpp|120|m_pWin->SetPage(buf);|
src\startherepage.cpp|125|bs->Add(m_pWin, 1, wxEXPAND);|
src\startherepage.cpp|133|//m_pWin->Destroy();|
src\startherepage.cpp|152|m_pWin->SetPage(buffer);|
src\startherepage.h|33|wxHtmlWindow* m_pWin;|
I put a trap in wxEVT_CREATE to catch the address of the htmlWindow.
I put another trap in wxEVT_DESTROY to try and catch it's destruction.
It never happened.
I then enable the "m_pWin->Destroy()" statement for a week. It seem to work fine, and the trap in my wxEVT_DESTROY saw it.
What am I missing?
doesn't wxWidgets automatically kill child windows when the parent is destroyed?
Yep, from the manual:
Do child windows get deleted automatically?
Yes, child windows are deleted from within the parent destructor. This includes any children that are themselves frames or dialogs, so you may wish to close these child frame or dialog windows explicitly from within the parent close handler.
Thanks for the tip. I guess an explicit Destroy() has to be issued on the window for it to show up in EVT_DESTROY();
tangentially related question: is there any way to show the start page without closing down open projects? (or to reopen the start page if it was closed)
It looks like the StartHerePage is deleted by main.cpp when a project is loaded. It's only re-created when all projects are closed.
main.cpp line 1765
bool show = !forceHasProject &&
Manager::Get()->GetProjectManager()->GetProjects()->GetCount() == 0 &&
Manager::Get()->GetConfigManager(_T("app"))->ReadBool(_T("/environment/start_here_page"), true);