Removed retain cycle from notification center. (flutter/engine#13073)
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user