IQKeyboardManager icon indicating copy to clipboard operation
IQKeyboardManager copied to clipboard

Reference that makes memory leak

Open vpavloviclevi9 opened this issue 1 year ago • 7 comments

Describe the bug Since version 7.0.0. (also with the latest version 7.0.2) IQKeyboardManager instance holds reference to the last focused text field even keyboard is dismissed, which makes memory leak and side effects on host application (as in my case). With version 6.5.16 no such issues.

To Reproduce Steps to reproduce the behavior: Initialize IQKeyboardManager in AppDelegate

IQKeyboardManager.shared.enable = true
IQKeyboardManager.shared.enableAutoToolbar = false
IQKeyboardManager.shared.resignOnTouchOutside = true

Ensure the text field is the focus and dismiss the keyboard. Transition to another ViewController, ensuring it's not retained in the navigation stack. Although the specific ViewController is no longer part of the view hierarchy, it remains in the memory graph, which causes a memory leak and in my case app side effects.

Expected behavior If keyboard is dismissed it shoudn't hold any reference to input fields.

Screenshots Here is the memory graph: image

Demo Project n/a

Versions

Xcode: 15.3 Mac OS: 14.4.1 Simulator/Device: both on simulator and device Simulator/Device Name: iPhone 15 Library Version: 7.0.0./ 7.0.1./ 7.0.2.

Additional context n/a

vpavloviclevi9 avatar Apr 10 '24 08:04 vpavloviclevi9

Thanks for reporting this issue. I'll investigate it and see why this is happening.

hackiftekhar avatar Apr 16 '24 18:04 hackiftekhar

IQKeyboardManager.shared.enable = true IQKeyboardManager.shared.enableAutoToolbar = false IQKeyboardManager.shared.resignOnTouchOutside = true

Pnaveen1513 avatar May 01 '24 12:05 Pnaveen1513

+1

yueno12 avatar May 28 '24 03:05 yueno12

@hackiftekhar any news on this?

vpavloviclevi9 avatar Jun 04 '24 06:06 vpavloviclevi9

I had the same problem

Sukarma33 avatar Jun 21 '24 18:06 Sukarma33

+1

NovichenkoAnton avatar Jun 25 '24 14:06 NovichenkoAnton

Same problem

artemborisenko avatar Jun 25 '24 14:06 artemborisenko

+1 I have the same problem. It holds any view controller with a UITextField in memory even after the view controller was popped.

mmatiush avatar Jul 02 '24 19:07 mmatiush

@hackiftekhar maybe you have any updates?

mmatiush avatar Jul 02 '24 19:07 mmatiush

I have tried to fixed the issue and pushed the code to master branch. However haven't tested my changes in different scenarios. So I would like to ask you guys to test the master branch version to see if you are able to still reproduce memory leaks in your situations and also test if everything works well for you. Till then I would like to keep this issue open.

hackiftekhar avatar Jul 16 '24 05:07 hackiftekhar

@hackiftekhar version 7.1.1 solved my problem, my problem was when setting the textfield to beFirstResponder, which causes a memory leak, thank you

Sukarma33 avatar Jul 19 '24 03:07 Sukarma33

Thanks @Sukarma33 for notifying that your problem is solved.

hackiftekhar avatar Jul 19 '24 09:07 hackiftekhar

I had the same problem, just hide keyboard before dismissing ViewController, it helped for me 😊

burhonoff avatar Jul 22 '24 12:07 burhonoff

The issue is still there, even with version 7.1.1

Someone else also has the same issue, so I'll leave this ticket closed.

https://github.com/hackiftekhar/IQKeyboardManager/issues/2055

vpavloviclevi9 avatar Sep 20 '24 04:09 vpavloviclevi9

I tried to fix it with some weak referencing and handled some pop gesture cases. Can you guys check master branch and see if issue is still there.

hackiftekhar avatar Sep 26 '24 07:09 hackiftekhar