Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set currentInput to nil to fix a memory leak #323

Merged
merged 1 commit into from
Jan 11, 2024

Conversation

kirillzyusko
Copy link
Owner

@kirillzyusko kirillzyusko commented Jan 10, 2024

📜 Description

Set currentInput to nil to fix a memory leak.

💡 Motivation and Context

If we store a reference as currentInput = UIResponder.current, then even if view is removed from the screen the view will not be deallocated (because we have a strong reference) and it'll be kind of memory leak (because view should be deallocated and free up a memory).

To fix this problem we need to remove a reference so ARC (automatic reference counter) will work properly and will deallocate view.

Actually it's not a very big problem, because users are switching between inputs frequently (and we overwrite a reference every time) so we have kind of have a constant memory allocation and it is not growing over time. Also we don't interact with this input anymore (don't call becomeFirstResponder and other methods), so it's kind of "safe".

📢 Changelog

iOS

  • set currentInput to nil in keyboardWillHide handler;

🤔 How Has This Been Tested?

Tested on iPhone 15 Pro (iOS 17.2) + e2e tests.

📸 Screenshots (if appropriate):

Before After
image image

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature.
lobis Luis Antonio Obis Aparicio
@kirillzyusko kirillzyusko added 🐛 bug Something isn't working 🍎 iOS iOS specific labels Jan 10, 2024
@kirillzyusko kirillzyusko self-assigned this Jan 10, 2024
Copy link
Contributor

📊 Package size report

Current size Target Size Difference
112265 bytes 112264 bytes 1 bytes 📈

@kirillzyusko kirillzyusko marked this pull request as ready for review January 10, 2024 19:52
@kirillzyusko kirillzyusko merged commit 6f055c9 into main Jan 11, 2024
10 checks passed
@kirillzyusko kirillzyusko deleted the fix/current-input-memory-leak branch January 11, 2024 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 🍎 iOS iOS specific
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant