Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@kangwang1988
Copy link
Contributor

Fix an issue that Flutter Engine can't be recycled as strongly referenced by NSMallocBlock

@kangwang1988
Copy link
Contributor Author

kangwang1988 commented Oct 10, 2019

Screen Shot 2019-10-10 at 6 10 16 PM

This issue is introduced in: 5075172fe

@kangwang1988 kangwang1988 requested review from dnfield and gaaclarke and removed request for gaaclarke October 10, 2019 16:11
dnfield
dnfield previously approved these changes Oct 10, 2019
Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

LGTM with nit.

This should let us re-enable the ios_add2app tests, which are currently failing because of this.

/cc @ianh @jmagman

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?

@dnfield
Copy link
Contributor

dnfield commented Oct 10, 2019

Needs formatting as well.

dnfield added a commit to flutter/flutter that referenced this pull request Oct 10, 2019
This would have caught the regression fixed in flutter/engine#13062

This can't land until that rolls in.

@ianh - If  this causes more problems for your upcoming sharding PR I'm happy to close it.
@dnfield dnfield dismissed their stale review October 10, 2019 17:11

@gaaclarke pointed out that the release is in the wrong class. He's going to add some more comments.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

Thanks for the catch but this change is erroneous. There isn't a remove observer to match the add observer. The one you've added is to the wrong class. This should be a 2 line fix. At line 178 add the following
__block FlutterEngine* blockSelf = self;
Then convert the call to:
[blockSelf notifyViewControllerDeallocated];

@kangwang1988
Copy link
Contributor Author

kangwang1988 commented Oct 10, 2019

Thanks for the catch but this change is erroneous. There isn't a remove observer to match the add observer. The one you've added is to the wrong class. This should be a 2 line fix. At line 178 add the following
__block FlutterEngine* blockSelf = self;
Then convert the call to:
[blockSelf notifyViewControllerDeallocated];

However, the fix you mentioned would need to set CLANG_ENABLE_OBJC_WEAK flag, or -fobjc-weak flag for the specific .mm file as it's a MRC file. I would rather prefer this fix.

@gaaclarke

_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 notifyViewControllerDeallocated];
}];
- (void)onFlutterVCWillDeallocNotif:(NSNotification *)aNotification {
[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.

@gaaclarke
Copy link
Member

fix you mentioned would need to set CLANG_ENABLE_OBJC_WEAK flag

Nope, because we are using __block not __weak.

@gaaclarke
Copy link
Member

Hey @kangwang1988 I've moved the fix over to #13073. I was having an offline discussion with @jmagman about issues related to this problem you found and it was just easier if I took control so I could work with her on your behalf. Thanks again for finding the issue, we should have this resolved by tomorrow.

@gaaclarke gaaclarke closed this Oct 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants