From 1e8724e6343d6b530c6d492357d75753b06d31f8 Mon Sep 17 00:00:00 2001
From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= <vslavik@fastmail.fm>
Date: Sat, 27 Jul 2002 18:14:47 +0000
Subject: [PATCH] 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
---
 docs/latex/wx/tapp.tex | 44 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

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}
-- 
2.47.2

