diff options
author | Gabriel de Dietrich <gabriel.dedietrich@qt.io> | 2017-11-20 13:43:38 -0800 |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dedietrich@qt.io> | 2017-12-26 21:43:43 +0000 |
commit | c7faa4ad8f466d330172f86795a4b36a80829ceb (patch) | |
tree | f28440f6d7807214a13e0d986bc70e27c5d539c6 /src/plugins | |
parent | a02b371eb2f34bf198c95cf0caa1fbad639f96bb (diff) |
Cocoa QPA: Delete singletons on exit
This involves QCocoaApplicationDelegate and QCocoaMenuLoader.
The former has been modernized to use blocks. The latter was
not being deleted previously.
Change-Id: Ic4cbfed2d9598fa04130675b3330d985b9489a21
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm | 41 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoamenuloader.mm | 8 |
2 files changed, 18 insertions, 31 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index 5392804d62..32be9ad4ee 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -86,16 +86,21 @@ QT_USE_NAMESPACE -QT_BEGIN_NAMESPACE -static QCocoaApplicationDelegate *sharedCocoaApplicationDelegate = nil; +@implementation QCocoaApplicationDelegate -static void cleanupCocoaApplicationDelegate() ++ (instancetype)sharedDelegate { - [sharedCocoaApplicationDelegate release]; + static QCocoaApplicationDelegate *shared = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + shared = [[self alloc] init]; + atexit_b(^{ + [shared release]; + shared = nil; + }); + }); + return shared; } -QT_END_NAMESPACE - -@implementation QCocoaApplicationDelegate - (id)init { @@ -120,7 +125,6 @@ QT_END_NAMESPACE - (void)dealloc { - sharedCocoaApplicationDelegate = nil; [dockMenu release]; if (reflectionDelegate) { [[NSApplication sharedApplication] setDelegate:reflectionDelegate]; @@ -131,27 +135,6 @@ QT_END_NAMESPACE [super dealloc]; } -+ (id)allocWithZone:(NSZone *)zone -{ - @synchronized(self) { - if (sharedCocoaApplicationDelegate == nil) { - sharedCocoaApplicationDelegate = [super allocWithZone:zone]; - qAddPostRoutine(cleanupCocoaApplicationDelegate); - return sharedCocoaApplicationDelegate; - } - } - return nil; -} - -+ (QCocoaApplicationDelegate *)sharedDelegate -{ - @synchronized(self) { - if (sharedCocoaApplicationDelegate == nil) - [[self alloc] init]; - } - return [[sharedCocoaApplicationDelegate retain] autorelease]; -} - - (void)setDockMenu:(NSMenu*)newMenu { [newMenu retain]; diff --git a/src/plugins/platforms/cocoa/qcocoamenuloader.mm b/src/plugins/platforms/cocoa/qcocoamenuloader.mm index 0d9bb5009d..fdca7297de 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuloader.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuloader.mm @@ -56,8 +56,12 @@ static QCocoaMenuLoader *shared = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - shared = [[self alloc] init]; - }); + shared = [[self alloc] init]; + atexit_b(^{ + [shared release]; + shared = nil; + }); + }); return shared; } |