Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS] Fix FlutterViewController retain cycle #42317

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -292,7 +292,7 @@ void OnKeyboardLayoutChanged(CFNotificationCenterRef center,

@implementation FlutterViewWrapper {
FlutterView* _flutterView;
FlutterViewController* _controller;
__weak FlutterViewController* _controller;
}

- (instancetype)initWithFlutterView:(FlutterView*)view
Expand Down
Expand Up @@ -69,6 +69,7 @@ - (bool)testViewWillAppearCalledMultipleTimes;
- (bool)testFlutterViewIsConfigured;
- (bool)testLookupKeyAssets;
- (bool)testLookupKeyAssetsWithPackage;
- (bool)testViewControllerIsReleased;

+ (void)respondFalseForSendEvent:(const FlutterKeyEvent&)event
callback:(nullable FlutterKeyEventCallback)callback
Expand Down Expand Up @@ -251,6 +252,10 @@ id MockGestureEvent(NSEventType type, NSEventPhase phase, double magnification,
ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testLookupKeyAssetsWithPackage]);
}

TEST(FlutterViewControllerTest, testViewControllerIsReleased) {
ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testViewControllerIsReleased]);
}

} // namespace flutter::testing

#pragma mark - FlutterViewControllerTestObjC
Expand Down Expand Up @@ -1016,4 +1021,24 @@ - (bool)testModifierKeysAreSynthesizedOnMouseMove {
return true;
}

- (bool)testViewControllerIsReleased {
__weak FlutterViewController* weakController;
@autoreleasepool {
id engineMock = flutter::testing::CreateMockFlutterEngine(@"");

FlutterRenderer* renderer_ = [[FlutterRenderer alloc] initWithFlutterEngine:engineMock];
OCMStub([engineMock renderer]).andReturn(renderer_);

FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engineMock
nibName:@""
bundle:nil];
[viewController loadView];
weakController = viewController;
}

EXPECT_EQ(weakController, nil);

return true;
}

@end