added a section on when to delete global objects

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16291 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2002-07-27 18:14:47 +00:00
parent 1233cee549
commit 1e8724e634

View File

@@ -54,3 +54,47 @@ construction time.
You can also use DECLARE\_APP(appClass) in a header file to declare the wxGetApp function which returns
a reference to the application object.
\subsection{Application shutdown}
\helpref{OnExit}{wxapponexit} is called when the application exits but {\it before}
wxWindows cleans its internal structures. Your should delete all wxWindows object that
your created by the time OnExit finishes. In particular, do {\bf not} destroy them
from application class' destructor!
For example, this code may crash:
\begin{verbatim}
class MyApp : public wxApp
{
public:
wxCHMHelpController m_helpCtrl;
...
};
\end{verbatim}
The reason for that is that {\tt m\_helpCtrl} is a member object and is
thus destroyed from MyApp destructor. But MyApp object is deleted after
wxWindows structures that wxCHMHelpController depends on were
uninitialized! The solution is to destroy HelpCtrl in {\it OnExit}:
\begin{verbatim}
class MyApp : public wxApp
{
public:
wxCHMHelpController *m_helpCtrl;
...
};
bool MyApp::OnInit()
{
...
m_helpCtrl = new wxCHMHelpController;
...
}
int MyApp::OnExit()
{
delete m_helpCtrl;
return 0;
}
\end{verbatim}