GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
authorDrew Gottlieb
Sun, 02 Dec 2012 17:23:13 +0100
changeset 8187 fa725fe25708
parent 8186 4ff8690df1b0
child 8188 4c166505e5c8
child 8189 328f429c3ecc
child 8190 92792d48574b
GCI2012: Find Out What is Causing This Problem (frontend leaks on OS X)
QTfrontend/main.cpp
--- 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;