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>
This commit is contained in:
parent
a02b371eb2
commit
c7faa4ad8f
@ -86,17 +86,22 @@
|
||||
|
||||
QT_USE_NAMESPACE
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
static QCocoaApplicationDelegate *sharedCocoaApplicationDelegate = nil;
|
||||
|
||||
static void cleanupCocoaApplicationDelegate()
|
||||
{
|
||||
[sharedCocoaApplicationDelegate release];
|
||||
}
|
||||
QT_END_NAMESPACE
|
||||
|
||||
@implementation QCocoaApplicationDelegate
|
||||
|
||||
+ (instancetype)sharedDelegate
|
||||
{
|
||||
static QCocoaApplicationDelegate *shared = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
shared = [[self alloc] init];
|
||||
atexit_b(^{
|
||||
[shared release];
|
||||
shared = nil;
|
||||
});
|
||||
});
|
||||
return shared;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super 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];
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user