-
Notifications
You must be signed in to change notification settings - Fork 6k
FlutterViewController notify will dealloc #12232
Conversation
generic and started turning off semantics when the view controller is remotely deleted.
| self.iosPlatformView->SetOwnerViewController(_viewController); | ||
| [self maybeSetupPlatformViewChannels]; | ||
|
|
||
| self.flutterViewControllerWillDeallocObserver = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is ok but consistency-wise seems a bit unnecessarily different. We already have _shell->GetPlatformView() all over the place in this file. Can't we just call _shell->GetPlatformView()->SetOwnerViewController(null) on notifyViewControllerDeallocated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not doing that because that would be changing behavior outside the bounds of the problem I was fixing. I'm just moving this file over to the new mechanism I created so we don't have multiple ways to do the same thing. The only logical change I made here was calling _viewController.reset() in notifyViewControllerDeallocated . I didn't technically have to do that to solve the bug, but it will almost certainly cause a bug in a future to keep a weak pointer to a dealloced object. This will turn that future bug to a null pointer exception which will be easier for someone to fix than calling a method into random memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline. Moving the direct plumbing to NSNotificationCenter is ok. If we're implicitly saying the precedent is also to promote moving other event plumbing to notification center.
|
This needs a test |
Done. I attempted to add a test for PlatformViewIOS inside of the ios unit tests target, there isn't an existing unit test for this class. It isn't possible to test because PlatformViewIOS makes reference to symbols inside of Flutter.framework that aren't exported so any unit test target that references PlatformViewIOS.h will fail to link. We need to come up with a better solution for testing internal c++ classes. |
xster
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Would be nice to add an integration test to scenario_apps too.
| [self destroyContext]; | ||
| } | ||
| _viewController.reset(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should only happen once right? Should we get rid of the observer here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could. I wouldn't recommend it. It would make more sense inside of the observer's block but it isn't necessary there either since the semantics of the message are that the object is dying, it shouldn't be dying twice.
|
|
||
| NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | ||
| [center removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; | ||
| [_flutterViewControllerWillDeallocObserver release]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a feeling if this happened before the view controller got dealloc'ed, it's probably a bug right? I don't think this can happen legitimately. Maybe we should print a message here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, that wouldn't be a bug. Releasing the observer detaches this object from the notification center for that message, so after that releasing the FlutterViewController will just not notify a FlutterEngine that he's being dealloc'd.
|
|
||
| extern NSNotificationName const FlutterViewControllerWillDealloc; | ||
|
|
||
| /// OCMock can't be used for FlutterEngine sometimes because it retains arguments to invocations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't understand this comment :D
Also, this is more a comment than a class doc right? Maybe //?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the text to be more clear. I think /// is appropriate since its intention is to be a docstring.
| if (ios_surface_ || !owner_controller) { | ||
| NotifyDestroyed(); | ||
| ios_surface_.reset(); | ||
| accessibility_bridge_.reset(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we get rid of that observer here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are getting rid of the observer a couple lines down, line 55. I don't believe there is any reason why it should be happening higher in the method.
| self.iosPlatformView->SetOwnerViewController(_viewController); | ||
| [self maybeSetupPlatformViewChannels]; | ||
|
|
||
| self.flutterViewControllerWillDeallocObserver = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline. Moving the direct plumbing to NSNotificationCenter is ok. If we're implicitly saying the precedent is also to promote moving other event plumbing to notification center.
I'll give this a stab on the bus. |
git@github.com:flutter/engine.git/compare/00c8941daeae...3f76f55 git log 00c8941..3f76f55 --no-merges --oneline 2019-09-15 iska.kaushik@gmail.com Revert "Roll src/third_party/dart a554c8be6b..d0052c1b31 (22 commits)" (flutter/engine#12290) 2019-09-14 30870216+gaaclarke@users.noreply.github.com FlutterViewController notify will dealloc (flutter/engine#12232) 2019-09-14 bkonyi@google.com Roll src/third_party/dart a554c8be6b..d0052c1b31 (22 commits) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC jimgraham@google.com on the revert to ensure that a human is aware of the problem. To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
git@github.com:flutter/engine.git/compare/00c8941daeae...3f76f55 git log 00c8941..3f76f55 --no-merges --oneline 2019-09-15 iska.kaushik@gmail.com Revert "Roll src/third_party/dart a554c8be6b..d0052c1b31 (22 commits)" (flutter/engine#12290) 2019-09-14 30870216+gaaclarke@users.noreply.github.com FlutterViewController notify will dealloc (flutter/engine#12232) 2019-09-14 bkonyi@google.com Roll src/third_party/dart a554c8be6b..d0052c1b31 (22 commits) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC jimgraham@google.com on the revert to ensure that a human is aware of the problem. To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
Made the FlutterViewController's dealloc notification more generic and started turning off semantics when the view controller is remotely deleted.
Relevant issue: flutter/flutter#33173