From 32e806fe7f0ca4ccee9924f4ded0a8be05de2b89 Mon Sep 17 00:00:00 2001 From: Kevin Ollivier Date: Thu, 5 Nov 2009 00:31:36 +0000 Subject: [PATCH] Create an autorelease pool to catch objects created during several special situations, like customized initialization, so that we don't leak there. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62557 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/app.h | 5 ++++- src/osx/carbon/app.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/wx/osx/app.h b/include/wx/osx/app.h index 2dc67c2566..24b2504b18 100644 --- a/include/wx/osx/app.h +++ b/include/wx/osx/app.h @@ -22,6 +22,7 @@ class WXDLLIMPEXP_FWD_CORE wxWindowMac; class WXDLLIMPEXP_FWD_CORE wxApp ; class WXDLLIMPEXP_FWD_CORE wxKeyEvent; class WXDLLIMPEXP_FWD_BASE wxLog; +class WXDLLIMPEXP_FWD_CORE wxMacAutoreleasePool; // Force an exit from main loop void WXDLLIMPEXP_CORE wxExit(); @@ -36,7 +37,7 @@ class WXDLLIMPEXP_CORE wxApp: public wxAppBase DECLARE_DYNAMIC_CLASS(wxApp) wxApp(); - virtual ~wxApp() {} + virtual ~wxApp(); virtual void WakeUpIdle(); @@ -61,6 +62,7 @@ class WXDLLIMPEXP_CORE wxApp: public wxAppBase protected: int m_printMode; // wxPRINT_WINDOWS, wxPRINT_POSTSCRIPT + wxMacAutoreleasePool* m_macPool; public: @@ -80,6 +82,7 @@ public: // we want to delete and cannot do it immediately // TODO change semantics to be in line with cocoa (make autrelease NOT increase the count) void MacAddToAutorelease( void* cfrefobj ); + void MacReleaseAutoreleasePool(); public: static wxWindow* s_captureWindow ; static long s_lastModifiers ; diff --git a/src/osx/carbon/app.cpp b/src/osx/carbon/app.cpp index 22dfa62edd..8e316a5621 100644 --- a/src/osx/carbon/app.cpp +++ b/src/osx/carbon/app.cpp @@ -1072,6 +1072,13 @@ wxApp::wxApp() m_macCurrentEvent = NULL ; m_macCurrentEventHandlerCallRef = NULL ; m_macEventPosted = NULL ; + m_macPool = new wxMacAutoreleasePool(); +} + +wxApp::~wxApp() +{ + if (m_macPool) + delete m_macPool; } CFMutableArrayRef GetAutoReleaseArray() @@ -1087,6 +1094,13 @@ void wxApp::MacAddToAutorelease( void* cfrefobj ) CFArrayAppendValue( GetAutoReleaseArray(), cfrefobj ); } +void wxApp::MacReleaseAutoreleasePool() +{ + if (m_macPool) + delete m_macPool; + m_macPool = new wxMacAutoreleasePool(); +} + void wxApp::OnIdle(wxIdleEvent& WXUNUSED(event)) { // If they are pending events, we must process them: pending events are -- 2.47.2