fix(iOS): memory leak caused by retain cycle in layout manager and input parser#513
Merged
kacperzolkiewski merged 2 commits intosoftware-mansion:mainfrom Apr 7, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a memory leak in the iOS implementation caused by retain cycles in the layout manager and input parser. The issue occurred because strong references to EnrichedTextInputView from LayoutManagerExtension and InputParser created circular references that prevented proper deallocation of these objects.
Changes:
- Introduces a new
WeakBoxutility class to wrap weak references for use with Objective-C associated objects - Updates
InputParserto use a__weakpointer instead of a strong reference for the input view - Updates
LayoutManagerExtensionto store the input reference viaWeakBoxto avoid the retain cycle while still maintaining the association
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| ios/utils/WeakBox.h | New header defining WeakBox interface with weak property |
| ios/utils/WeakBox.m | WeakBox implementation (auto-synthesized properties) |
| ios/inputParser/InputParser.mm | Changed _input from strong to __weak reference |
| ios/extensions/LayoutManagerExtension.mm | Updated to use WeakBox wrapper and corrected imports |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
kacperzolkiewski
approved these changes
Apr 7, 2026
Collaborator
kacperzolkiewski
left a comment
There was a problem hiding this comment.
Thank you for your contribution!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The issue was caused by a strong associated reference (input) inside LayoutManagerExtension and Input parser, which retained EnrichedTextInputView. Since the input view also indirectly retains the layout manager and parser, this created a retain cycle and prevented proper deallocation.
The fix replaces the strong associated object with a weak reference using a WeakBox wrapper and __weak annotation for input in the parser. This allows ARC to correctly release EnrichedTextInputView and related objects when they are no longer needed.
Test Plan
Screenshots / Videos
Before:
Screen.Recording.2026-04-03.at.12.44.47.mov
After
Screen.Recording.2026-04-03.at.12.47.53.mov
Compatibility
Checklist