Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
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
19 changes: 17 additions & 2 deletions shell/platform/darwin/ios/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -176,15 +179,27 @@ - (void)setViewController:(FlutterViewController*)viewController {
self.iosPlatformView->SetOwnerViewController(_viewController);
[self maybeSetupPlatformViewChannels];

__block FlutterEngine* blockSelf = self;
Copy link
Member

Choose a reason for hiding this comment

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

🔮 The retain cycle will be reintroduced when someone finally hits the "modernize to ARC" button without auditing all the blocks where weak memory management is expected. 🔮

Copy link
Member Author

Choose a reason for hiding this comment

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

New word, "retro-modernize"? When we move to ARC it should work as well. There is a subtle difference between __block and __weak (like how they treat primitives). For an object pointer it should behave the same. I'm more sure about that than my understanding of the addObserverForName:object:queue:usingBlock: but obviously I've been wrong before, haha.

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];
Expand Down