QTfrontend/main.cpp
changeset 8187 fa725fe25708
parent 8117 329d9756b57c
child 8206 1633a6510834
--- a/QTfrontend/main.cpp	Sun Dec 02 17:01:51 2012 +0100
+++ b/QTfrontend/main.cpp	Sun Dec 02 17:23:13 2012 +0100
@@ -105,8 +105,28 @@
     return true;
 }
 
+#ifdef __APPLE__
+static CocoaInitializer *cocoaInit = NULL;
+// Function to be called at end of program's termination on OS X to release
+// the NSAutoReleasePool contained within the CocoaInitializer.
+void releaseCocoaPool(void)
+{
+    if (cocoaInit != NULL)
+    {
+        delete cocoaInit;
+        cocoaInit = NULL;
+    }
+}
+#endif
+
 int main(int argc, char *argv[])
 {
+#ifdef __APPLE__
+    // This creates the autoreleasepool that prevents leaking, and destroys it only on exit
+    cocoaInit = new CocoaInitializer();
+    atexit(releaseCocoaPool);
+#endif
+
     HWApplication app(argc, argv);
 
     FileEngineHandler engine(argv[0]);
@@ -254,10 +274,6 @@
         registry_hklm.setValue("Software/Hedgewars/Path", bindir->absolutePath().replace("/", "\\"));
     }
 #endif
-#ifdef __APPLE__
-    // this creates the autoreleasepool that prevents leaking
-    CocoaInitializer initializer;
-#endif
 
     QString style = "";
     QString fname;