IQKeyboardManager icon indicating copy to clipboard operation
IQKeyboardManager copied to clipboard

Memory leak after touching a UITextField

Open mmatiush opened this issue 7 months ago • 10 comments

Describe the bug The view controller containing a UITextField is not deinitialized after you pop the view controller on condition that you interacted with the UITextField (touched it).

To Reproduce Steps to reproduce the behavior:

  1. Start an app that has one view controller (VC1) embedded in a navigation view controller
  2. VC1 should call IQKeyboardManager.shared.enable = true on viewDidLoad
  3. From VC1 push a VC2 that has a UITextField on it
  4. Touch the UITextField
  5. Swipe back to pop, or tap the back button to pop the VC2
  6. Check memory graph to see the that the VC2 is retained in the memory (or check for missing debug print from VC2's deinit)

Expected behavior VC2 is deinitialized after it's popped.

Demo Project TextFieldLeak.zip

I have a ViewController (initial VC1) and a ChatViewController (VC2) that contains a UITextField. I've added the debug prints on ChatViewController to see when it's loaded and deinitialized.

Screenshots

There some system warnings, but the deinit is no called. CleanShot 2024-07-04 at 15 12 26

Memory graph after popping the ChatViewController CleanShot 2024-07-04 at 15 21 38

Versions

Xcode: 15.4 Mac OS: Sonoma 14.3.1 Device: 17.3.1 Device Name: iPhone 14 Pro Library Version: 7.0.3

Additional context

If IQKeyboardManager is not enabled, the ChatViewController is not retained. // IQKeyboardManager.shared.enable = true

On iPhone 12 mini with iOS 15.3.1 the bug is reproduced only if you swipe back to pop the view controller with the text field. If you tap the back button, the view controller is successfully deinitialized.

If you tap any other text field in the app, the ChatViewController will be deinited.

mmatiush avatar Jul 04 '24 12:07 mmatiush