hackiftekhar / IQKeyboardManager

Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView. Neither need to write any code nor any setup required and much more.
MIT License
16.43k stars 2.41k forks source link

Memory leak after touching a UITextField #2055

Open mmatiush opened 2 months ago

mmatiush commented 2 months ago

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.

hackiftekhar commented 1 month ago

I did a few changes, can you please check this again with the current master branch version?

hackiftekhar commented 1 month ago

I tested the demo project and it's still looks to be working correctly with current version. However I did a few fixes so please check it again. I think it should not produce any leaks now.

mmatiush commented 1 month ago

@hackiftekhar I've installed the master brach commit 82aa948.

It partially fixed the issue.

Now the ChatViewController is successfully deinited when you: 1) Tap on the back button (it worked this way the iOS 15.3.1, but now it also works on 17.3.1) 2) Hide the keyboard and swipe back to pop

The problem remains: 1) Keyboard is not hidden and you swipe back to pop

mmatiush commented 1 month ago

@hackiftekhar do you think could you check it again and reopen the issue? I can get more details if needed

hackiftekhar commented 1 month ago

Sure @mmatiush. I'm here to help.

hackiftekhar commented 1 month ago

I'm unable to reproduce the mentioned issue. This is what I did

Result: In my case the keyboard get's successfully dismissed.

mmatiush commented 1 month ago

@hackiftekhar Sorry for the confusion in the source code. Please uncomment this line to enable the library and the issue will be reproduced CleanShot 2024-08-02 at 16 44 16

hackiftekhar commented 1 month ago

Yeah, you are right, it doesn't work the way it should.

mmatiush commented 2 weeks ago

@hackiftekhar do you think it can be fixed?

hackiftekhar commented 2 weeks ago

I need to look at it again to find the solution. I'm always here to fix issue caused due to IQKeyboardManager.