IQKeyboardManager
IQKeyboardManager copied to clipboard
Memory leak after touching a UITextField
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:
- Start an app that has one view controller (VC1) embedded in a navigation view controller
- VC1 should call
IQKeyboardManager.shared.enable = true
on viewDidLoad - From VC1 push a VC2 that has a UITextField on it
- Touch the UITextField
- Swipe back to pop, or tap the back button to pop the VC2
- 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.
Memory graph after popping the ChatViewController
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.