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

Memory usage increases exponentially with each opening of ModalBottomSheet on iOS #4626

Closed
robxyy opened this issue Apr 16, 2024 · 4 comments · Fixed by JetBrains/compose-multiplatform-core#1292
Assignees
Labels
bug Something isn't working p:high High priority regression reproduced

Comments

@robxyy
Copy link
Contributor

robxyy commented Apr 16, 2024

Describe the bug
Memory usage increases exponentially with each opening of ModalBottomSheet on iOS

Affected platforms

  • iOS

Versions

  • Kotlin version*: 1.9.23
  • Compose Multiplatform version*: 1.6.2, 1.6.10-dev1583
  • OS version(s)* (required for Desktop and iOS issues): 17.4.1
  • Device (model or simulator for iOS issues): model

To Reproduce

@Composable
fun App() {
  MaterialTheme {
    var openBottomSheet by remember { mutableStateOf(false) }
    Button(onClick = {
      openBottomSheet = true
    }) {
      Text("ModalBottomSheet3")
    }

    if (openBottomSheet) {
      val sheetState = rememberModalBottomSheetState()
      ModalBottomSheet(
        onDismissRequest = {
          openBottomSheet = false
        },
        sheetState = sheetState,
      ) {
        Text("ModalBottomSheet3", Modifier.height(200.dp))
      }
    }
  }
}

Expected behavior
Normal memory growth

Screenshots
image

@robxyy robxyy added bug Something isn't working submitted labels Apr 16, 2024
@terrakok terrakok assigned terrakok and elijah-semyonov and unassigned terrakok Apr 17, 2024
@robxyy
Copy link
Contributor Author

robxyy commented Apr 19, 2024

After setting platformLayers to false, memory returned to normal growth.

@elijah-semyonov
Copy link
Contributor

Yes, thank you! We've already proved, that the machinery responsible for Dialogs/Popups layers somehow leaks the memory, investigating it.

@elijah-semyonov
Copy link
Contributor

Bisected a regression point:
JetBrains/compose-multiplatform-core#1082

elijah-semyonov added a commit to JetBrains/compose-multiplatform-core that referenced this issue Apr 19, 2024
## Proposed Changes

Remove views from superviews to break some retain cycle.

## Testing

Test: TODO

## Issues Fixed

Fixes: JetBrains/compose-multiplatform#4626
MatkovIvan pushed a commit to JetBrains/compose-multiplatform-core that referenced this issue Apr 22, 2024
## Proposed Changes

Replace `CGColorCreate` with `UIColor.clearColor.CGColor`

## Testing

Test: Frequently open ModalBottomSheet or Popup, and then view memory
leak information in `Instruments`.

Fix before:
<img width="720" alt="image"
src="https://github.com/JetBrains/compose-multiplatform-core/assets/9105106/958839b6-9abd-4dbe-8ae2-6ed08412c8ab">

## Issues Fixed

Fixes: This is part of
JetBrains/compose-multiplatform#4626
@okushnikov
Copy link
Collaborator

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p:high High priority regression reproduced
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants