Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ @interface FlutterEngine () <FlutterTextInputDelegate, FlutterBinaryMessenger>
@property(nonatomic, readonly) NSMutableDictionary* pluginPublications;

@property(nonatomic, readwrite, copy) NSString* isolateId;
@property(nonatomic, retain) id<NSObject> flutterViewControllerWillDeallocObserver;
@end

@interface FlutterEngineRegistrar : NSObject <FlutterPluginRegistrar>
Expand Down Expand Up @@ -118,7 +117,6 @@ - (void)dealloc {

NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
[_flutterViewControllerWillDeallocObserver release];

[super dealloc];
}
Expand Down Expand Up @@ -175,14 +173,11 @@ - (void)setViewController:(FlutterViewController*)viewController {
_viewController = [viewController getWeakPtr];
self.iosPlatformView->SetOwnerViewController(_viewController);
[self maybeSetupPlatformViewChannels];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFlutterVCWillDeallocNotif:) name:FlutterViewControllerWillDealloc object:viewController];
Copy link
Member

@jmagman jmagman Oct 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't removing the observer for the previous viewController.

- (void)setViewController:(FlutterViewController*)viewController {
  if (_viewController == viewController) {
    return;
  }
  FML_DCHECK(self.iosPlatformView);
  if (_viewController) {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:FlutterViewControllerWillDealloc object:_viewController];
  }
   _viewController = [viewController getWeakPtr];
...

}

self.flutterViewControllerWillDeallocObserver =
[[NSNotificationCenter defaultCenter] addObserverForName:FlutterViewControllerWillDealloc
object:viewController
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification* note) {
[self notifyViewControllerDeallocated];
}];
- (void)onFlutterVCWillDeallocNotif:(NSNotification *)aNotification {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: avoid abbreviations - maybe just onFlutterViewControllerWillDealloc?

[self notifyViewControllerDeallocated];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to have this new method at all? Can you add a notification parameter to notifyViewControllerDeallocated (assuming this isn't exposed in a header, I'm not looking at the code at the moment)

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notifyViewControllerDeallocated:) name:FlutterViewControllerWillDealloc object:viewController];
- (void)notifyViewControllerDeallocated:(NSNotification *)notification {

Also, does this still need to dispatch to the mainQueue if this isn't the main queue? There's no guarantee about what queue the notification will be posted on.

}

- (void)notifyViewControllerDeallocated {
Expand Down Expand Up @@ -638,6 +633,7 @@ - (instancetype)initWithPlugin:(NSString*)pluginKey flutterEngine:(FlutterEngine
}

- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[_pluginKey release];
[_flutterEngine release];
[super dealloc];
Expand Down