diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm index a135c4fcc7f19..1e04170da2159 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.mm @@ -387,8 +387,8 @@ - (void)dealloc { } - (UITextField*)textField { - if (_textField == nil) { - _textField = [[[UITextField alloc] init] autorelease]; + if (!_textField) { + _textField = [[UITextField alloc] init]; } return _textField; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m index 21b1d1cf5ae36..7f69a19664de1 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m +++ b/shell/platform/darwin/ios/framework/Source/FlutterTextInputPluginTest.m @@ -17,6 +17,10 @@ - (void)setTextInputState:(NSDictionary*)state; - (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 @@ - (void)testUITextInputCallsUpdateEditingStateOnce { [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