X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1233cee549942a5320788a5650eb805cdf26530c..1e8724e6343d6b530c6d492357d75753b06d31f8:/docs/latex/wx/tapp.tex diff --git a/docs/latex/wx/tapp.tex b/docs/latex/wx/tapp.tex index f9f7ef4026..8bef4289fa 100644 --- a/docs/latex/wx/tapp.tex +++ b/docs/latex/wx/tapp.tex @@ -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}