From 45ac2b64e6ce14157e4fef5d52bf4628f7e66787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E6=B4=B5=E9=94=8B?= Date: Thu, 6 Jul 2023 01:00:18 +0800 Subject: [PATCH] [iOS] Fix FlutterViewController retain cycle (flutter/engine#43379) Fixes [flutter/flutter#126560](https://github.com/flutter/flutter/issues/126560) --- .../ios/framework/Source/FlutterTextInputPlugin.mm | 2 +- .../ios/framework/Source/FlutterViewControllerTest.mm | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index 2463a17f78..625a4d4bf0 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -2190,7 +2190,7 @@ static BOOL IsSelectionRectBoundaryCloserToPoint(CGPoint point, NSMutableDictionary* autofillContext; @property(nonatomic, retain) FlutterTextInputView* activeView; @property(nonatomic, retain) FlutterTextInputViewAccessibilityHider* inputHider; -@property(nonatomic, readonly) id viewResponder; +@property(nonatomic, readonly, weak) id viewResponder; @end @implementation FlutterTextInputPlugin { diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm index f20e2280ce..54bca88f57 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterViewControllerTest.mm @@ -1055,6 +1055,16 @@ extern NSNotificationName const FlutterViewControllerWillDealloc; OCMVerify([self.mockEngine binaryMessenger]); } +- (void)testViewControllerIsReleased { + __weak FlutterViewController* weakViewController; + @autoreleasepool { + FlutterViewController* viewController = [[FlutterViewController alloc] init]; + weakViewController = viewController; + [viewController viewDidLoad]; + } + XCTAssertNil(weakViewController); +} + #pragma mark - Platform Brightness - (void)testItReportsLightPlatformBrightnessByDefault {