From 780b6766d9f0836a213b1702ec97f19b6be73ba8 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Thu, 10 Oct 2019 17:12:51 -0700 Subject: [PATCH 1/2] Removed retain cycle from notification center. --- shell/platform/darwin/ios/framework/Source/FlutterEngine.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 3aa559414c6f5..e673b99ab3e6e 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -176,12 +176,13 @@ - (void)setViewController:(FlutterViewController*)viewController { 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]; }]; } From 020db5845550dfbcc117439e706e41cc8dbbfdcc Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Thu, 10 Oct 2019 18:13:14 -0700 Subject: [PATCH 2/2] added removeobservers --- .../darwin/ios/framework/Source/FlutterEngine.mm | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index e673b99ab3e6e..2711e2e9b82ab 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -118,7 +118,10 @@ - (void)dealloc { NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; [center removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; - [_flutterViewControllerWillDeallocObserver release]; + if (_flutterViewControllerWillDeallocObserver) { + [center removeObserver:_flutterViewControllerWillDeallocObserver]; + [_flutterViewControllerWillDeallocObserver release]; + } [super dealloc]; } @@ -186,6 +189,17 @@ - (void)setViewController:(FlutterViewController*)viewController { }]; } +- (void)setFlutterViewControllerWillDeallocObserver:(id)observer { + if (observer != _flutterViewControllerWillDeallocObserver) { + if (_flutterViewControllerWillDeallocObserver) { + [[NSNotificationCenter defaultCenter] + removeObserver:_flutterViewControllerWillDeallocObserver]; + [_flutterViewControllerWillDeallocObserver release]; + } + _flutterViewControllerWillDeallocObserver = [observer retain]; + } +} + - (void)notifyViewControllerDeallocated { if (!_allowHeadlessExecution) { [self destroyContext];