#import <AppKit/NSApplication.h>
 #import <Foundation/NSRunLoop.h>
 #import <Foundation/NSArray.h>
+#import <Foundation/NSAutoreleasePool.h>
 
 // ----------------------------------------------------------------------------
 // globals
 @end // wxPoserNSApplication
 WX_IMPLEMENT_POSER(wxPoserNSApplication);
 
+class wxAutoNSAutoreleasePool
+{
+public:
+    wxAutoNSAutoreleasePool()
+    {
+        m_pool = [[NSAutoreleasePool alloc] init];
+    }
+    ~wxAutoNSAutoreleasePool()
+    {
+        [m_pool release];
+    }
+protected:
+    NSAutoreleasePool *m_pool;
+};
+
 // ============================================================================
 // functions
 // ============================================================================
 
 bool wxApp::Initialize(int& argc, wxChar **argv)
 {
+    wxAutoNSAutoreleasePool pool;
     // Mac OS X passes a process serial number command line argument when
     // the application is launched from the Finder. This argument must be
     // removed from the command line arguments before being handled by the
 
 bool wxApp::OnInitGui()
 {
+    wxAutoNSAutoreleasePool pool;
     if(!wxAppBase::OnInitGui())
         return FALSE;
 
     return TRUE;
 }
 
+bool wxApp::CallOnInit()
+{
+    wxAutoNSAutoreleasePool pool;
+    return OnInit();
+}
+
 bool wxApp::OnInit()
 {
     if(!wxAppBase::OnInit())