Skip to content

Commit

Permalink
macOS: Fix FlutterViewController retain cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
knopp committed May 25, 2023
1 parent e97d841 commit 5260196
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
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

0 comments on commit 5260196

Please sign in to comment.