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

iOS ComposeWindow memory leak fix #728

Merged
merged 7 commits into from
Aug 8, 2023
Merged

Conversation

elijah-semyonov
Copy link

@elijah-semyonov elijah-semyonov commented Aug 3, 2023

Proposed Changes

Imply ownership semantics in ComposeWindow.ios.kt and wrap child->parent references into WeakReference.
Replace all places where this is explicitly captured by accessing ComposeWindow dynamic properties with explicit weakThis.get()?._property_name_, capture newly created references to properties with non-value-semantics (such as MutableState) directly in the scope where lambda is created to avoid implicit this capture and introducing nullable types for CompositionLocal

Testing

Test: automatic test TBD.

Manual testing: launch project from Xcode, tap "Native modal with navigation", "Present popup", push several new ComposeWindows tapping "Push" button, dismiss the modal using swipe-down interaction. Repeat multiple times.
Open memory graph debug, ensure that ComposeWindow count is less than amount that was spawned previously.

Issues Fixed

Fixes: leaking ComposeWindow.

Depends on

JetBrains/skiko#771

## API Change Reverted in #747
LocalUIViewController type changed from ProvidableCompositionLocal<UIViewController> to ProvidableCompositionLocal<WeakReference<LocalUIViewController>>

@elijah-semyonov elijah-semyonov merged commit 1071df2 into jb-main Aug 8, 2023
3 checks passed
@elijah-semyonov elijah-semyonov deleted the es/ios-memory-leak-fix branch August 8, 2023 10:16
elijah-semyonov added a commit that referenced this pull request Aug 11, 2023
igordmn pushed a commit that referenced this pull request Aug 11, 2023
## Proposed Changes

Revert [memory leak fix PR](#728)
Implement eager dispose on `viewDidDisappear`, reconstruct scene on `viewWillAppear`

## Testing

Test: same as reverted PR

## API Changes
`ComposeUIViewController` now disposes the composition on `viewDidDisappear` and reconstructs it on `viewWillAppear`.
Clients should keep the important state outside of the composition and composition should subscribe to it:
```
class MyScreenState {
    var title by mutableStateOf("Title")
        private set
}

val state = MyScreenState()
val viewController = ComposeUIViewController {
    Text(state.title)
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants