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 a135c4fcc7..1e04170da2 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 @@ -387,8 +387,8 @@ static FlutterAutofillType autofillTypeOf(NSDictionary* configuration) { } - (UITextField*)textField { - if (_textField == nil) { - _textField = [[[UITextField alloc] init] autorelease]; + if (!_textField) { + _textField = [[UITextField alloc] init]; } return _textField; } diff --git a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m index 21b1d1cf5a..7f69a19664 100644 --- a/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m +++ b/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m @@ -17,6 +17,10 @@ FLUTTER_ASSERT_ARC - (BOOL)isVisibleToAutofill; @end +@interface FlutterSecureTextInputView : FlutterTextInputView +@property(nonatomic, strong) UITextField* textField; +@end + @interface FlutterTextInputPlugin () @property(nonatomic, strong) FlutterTextInputView* reusableInputView; @property(nonatomic, assign) FlutterTextInputView* activeView; @@ -496,4 +500,15 @@ FLUTTER_ASSERT_ARC [inputView unmarkText]; XCTAssertEqual(updateCount, 6); } + +- (void)testNoZombies { + // Regression test for https://github.com/flutter/flutter/issues/62501. + FlutterSecureTextInputView* passwordView = [[FlutterSecureTextInputView alloc] init]; + + @autoreleasepool { + // Initialize the lazy textField. + [passwordView.textField description]; + } + XCTAssert([[passwordView.textField description] containsString:@"TextField"]); +} @end