Clean up QCocoaIntegration destruction.
authorMorten Johan Sorvig <morten.sorvig@nokia.com>
Fri, 13 Jan 2012 12:46:30 +0000 (13:46 +0100)
committerQt by Nokia <qt-info@nokia.com>
Sat, 14 Jan 2012 04:36:12 +0000 (05:36 +0100)
Fix memory leak - delete the font database. Remove
the NAApplication delegate.

Change-Id: I7c69eb4df01c8450c0abde360f77fbb318b20c83
Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
src/plugins/platforms/cocoa/qcocoaintegration.h
src/plugins/platforms/cocoa/qcocoaintegration.mm

index dd0c4ae..46e8925 100644 (file)
@@ -47,6 +47,7 @@
 #include "qcocoaautoreleasepool.h"
 #include "qcocoacursor.h"
 
+#include <QtCore/QScopedPointer>
 #include <QtGui/QPlatformIntegration>
 
 QT_BEGIN_NAMESPACE
@@ -90,11 +91,12 @@ public:
 
     QPlatformTheme *platformTheme() const;
 private:
-    QPlatformFontDatabase *mFontDb;
+
+    QScopedPointer<QPlatformFontDatabase> mFontDb;
     QAbstractEventDispatcher *mEventDispatcher;
 
-    QPlatformAccessibility *mAccessibility;
-    QPlatformTheme *mPlatformTheme;
+    QScopedPointer<QPlatformAccessibility> mAccessibility;
+    QScopedPointer<QPlatformTheme> mPlatformTheme;
 };
 
 QT_END_NAMESPACE
index 7d91be7..685b640 100644 (file)
@@ -89,6 +89,9 @@ QCocoaScreen::~QCocoaScreen()
 QCocoaIntegration::QCocoaIntegration()
     : mFontDb(new QCoreTextFontDatabase())
     , mEventDispatcher(new QCocoaEventDispatcher())
+    , mAccessibility(new QPlatformAccessibility)
+    , mPlatformTheme(new QCocoaTheme)
+
 {
     QCocoaAutoReleasePool pool;
 
@@ -134,13 +137,11 @@ QCocoaIntegration::QCocoaIntegration()
         screenAdded(screen);
     }
 
-    mAccessibility = new QPlatformAccessibility;
-    mPlatformTheme = new QCocoaTheme;
 }
 
 QCocoaIntegration::~QCocoaIntegration()
 {
-    delete mAccessibility;
+    [[NSApplication sharedApplication] setDelegate: 0];
 }
 
 bool QCocoaIntegration::hasCapability(QPlatformIntegration::Capability cap) const
@@ -177,7 +178,7 @@ QAbstractEventDispatcher *QCocoaIntegration::guiThreadEventDispatcher() const
 
 QPlatformFontDatabase *QCocoaIntegration::fontDatabase() const
 {
-    return mFontDb;
+    return mFontDb.data();
 }
 
 QPlatformNativeInterface *QCocoaIntegration::nativeInterface() const
@@ -187,12 +188,12 @@ QPlatformNativeInterface *QCocoaIntegration::nativeInterface() const
 
 QPlatformAccessibility *QCocoaIntegration::accessibility() const
 {
-    return mAccessibility;
+    return mAccessibility.data();
 }
 
 QPlatformTheme *QCocoaIntegration::platformTheme() const
 {
-    return mPlatformTheme;
+    return mPlatformTheme.data();
 }
 
 QT_END_NAMESPACE