Removed retain cycle from notification center. (flutter/engine#13073)

This commit is contained in:
gaaclarke
2019-10-11 11:34:11 -07:00
committed by GitHub
parent e5b04b4ddc
commit 48ab41ac63

View File

@@ -118,7 +118,10 @@ NSString* const FlutterDefaultDartEntrypoint = nil;
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
[_flutterViewControllerWillDeallocObserver release];
if (_flutterViewControllerWillDeallocObserver) {
[center removeObserver:_flutterViewControllerWillDeallocObserver];
[_flutterViewControllerWillDeallocObserver release];
}
[super dealloc];
}
@@ -176,15 +179,27 @@ NSString* const FlutterDefaultDartEntrypoint = nil;
self.iosPlatformView->SetOwnerViewController(_viewController);
[self maybeSetupPlatformViewChannels];
__block FlutterEngine* blockSelf = self;
self.flutterViewControllerWillDeallocObserver =
[[NSNotificationCenter defaultCenter] addObserverForName:FlutterViewControllerWillDealloc
object:viewController
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification* note) {
[self notifyViewControllerDeallocated];
[blockSelf notifyViewControllerDeallocated];
}];
}
- (void)setFlutterViewControllerWillDeallocObserver:(id<NSObject>)observer {
if (observer != _flutterViewControllerWillDeallocObserver) {
if (_flutterViewControllerWillDeallocObserver) {
[[NSNotificationCenter defaultCenter]
removeObserver:_flutterViewControllerWillDeallocObserver];
[_flutterViewControllerWillDeallocObserver release];
}
_flutterViewControllerWillDeallocObserver = [observer retain];
}
}
- (void)notifyViewControllerDeallocated {
if (!_allowHeadlessExecution) {
[self destroyContext];