-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 leak in SnapshotStateObserver? #1969
Memory leak in SnapshotStateObserver? #1969
Comments
A bit of extra details to add. In |
This appears similar to a problem I have been investigating, though my problem occurs on Android with Jetpack Compose. Some details here |
There is a related bug report for Jetpack Compose: https://issuetracker.google.com/issues/223222717 |
@mnonnenmacher thanks for sharing, that's very good to know! Hopefully will be fixed soon in upstream. |
I believe the problem is in the On every invocation of the fun performUpdate() {
snapshotObserver.observeReads(
Unit,
onValueChangedForScope = { tasks.trySend(::performUpdate) }
) {
currentUpdate()
}
} I replaced this declaration with the following and the memory leak disappeared: lateinit var onValueChangedForScope: (Unit) -> Unit
fun performUpdate() {
snapshotObserver.observeReads(
Unit,
onValueChangedForScope = onValueChangedForScope,
) {
currentUpdate()
}
}
onValueChangedForScope = { tasks.trySend(::performUpdate) } |
There's no real movement in related Google ticket: https://issuetracker.google.com/issues/223222717 |
I posted the following already at the google issue tracker: The memory leak is still present in Compose 1.2.0 with Kotlin 1.7.20.
PS: .jfr files can be viewed with JDK Mission Control (https://github.com/openjdk/jmc) |
I have the same issue. Constant high-frequency UI updates cause memory leak. |
@pema4 Does your solution with gradle task patch work with Compose 1.2.0 version (maybe you already migrated)? |
@igordmn please, take a closer look at this problem. |
Thanks for pointing at this issue, we'll take a look. |
If there are animations on the screen, after some time we will encounter performance degradation, and an increased memory consumption. This fix is similar to the other fix in the past (https://android-review.googlesource.com/c/platform/frameworks/support/+/1398690). We have to remember the lambda instead of creating it each time. Fixes JetBrains/compose-multiplatform#2455 Fixes JetBrains/compose-multiplatform#1969 The tests are not very deterministic, but it seems better to have them than not to have. The second test fails before the fix, and passes after the fix. We will see if they will be stable on our CI or not. If they will be flaky, we will tune them, or remove them.
Thanks to all for investigating this issue! And especially @pema4 for the fix. It is fixed, and the fix will be in 1.3.0 (or in 1.2.2, we will decide soon). |
Terrific! Can't wait for release! |
If there are animations on the screen, after some time we will encounter performance degradation, and an increased memory consumption. This fix is similar to the other fix in the past (https://android-review.googlesource.com/c/platform/frameworks/support/+/1398690). We have to remember the lambda instead of creating it each time. Fixes JetBrains/compose-multiplatform#2455 Fixes JetBrains/compose-multiplatform#1969 The tests are not very deterministic, but it seems better to have them than not to have. The second test fails before the fix, and passes after the fix. We will see if they will be stable on our CI or not. If they will be flaky, we will tune them, or remove them.
If there are animations on the screen, after some time we will encounter performance degradation, and an increased memory consumption. This fix is similar to the other fix in the past (https://android-review.googlesource.com/c/platform/frameworks/support/+/1398690). We have to remember the lambda instead of creating it each time. Fixes JetBrains/compose-multiplatform#2455 Fixes JetBrains/compose-multiplatform#1969 The tests are not very deterministic, but it seems better to have them than not to have. The second test fails before the fix, and passes after the fix. We will see if they will be stable on our CI or not. If they will be flaky, we will tune them, or remove them.
If there are animations on the screen, after some time we will encounter performance degradation, and an increased memory consumption. This fix is similar to the other fix in the past (https://android-review.googlesource.com/c/platform/frameworks/support/+/1398690). We have to remember the lambda instead of creating it each time. Fixes JetBrains/compose-multiplatform#2455 Fixes JetBrains/compose-multiplatform#1969 The tests are not very deterministic, but it seems better to have them than not to have. The second test fails before the fix, and passes after the fix. We will see if they will be stable on our CI or not. If they will be flaky, we will tune them, or remove them.
If there are animations on the screen, after some time we will encounter performance degradation, and an increased memory consumption. This fix is similar to the other fix in the past (https://android-review.googlesource.com/c/platform/frameworks/support/+/1398690). We have to remember the lambda instead of creating it each time. Fixes JetBrains/compose-multiplatform#2455 Fixes JetBrains/compose-multiplatform#1969 The tests are not very deterministic, but it seems better to have them than not to have. The second test fails before the fix, and passes after the fix. We will see if they will be stable on our CI or not. If they will be flaky, we will tune them, or remove them.
If there are animations on the screen, after some time we will encounter performance degradation, and an increased memory consumption. This fix is similar to the other fix in the past (https://android-review.googlesource.com/c/platform/frameworks/support/+/1398690). We have to remember the lambda instead of creating it each time. Fixes JetBrains#2455 Fixes JetBrains#1969 The tests are not very deterministic, but it seems better to have them than not to have. The second test fails before the fix, and passes after the fix. We will see if they will be stable on our CI or not. If they will be flaky, we will tune them, or remove them.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks. |
Hi JB team,
I'm trying to get up with a desktop app which updates small part of UI quite frequently (e.g. a timer). As result of app's normal operation, memory consumption grows relatively quickly. Profiling points to
SnapshotStateObserver
, which seem doesn't release some state. However, I don't see a way how to control that or set a limit.After just half an hour of work, memory trend is clear:
On below screenshot you may see Live Bytes and Objects, the max numbers there constantly grow:
Sample app source:
OS: Manjaro Linux
Compose: 1.1.0
OpenJDK: 11.0.15
Looking forward hearing back from you. Thanks!
The text was updated successfully, but these errors were encountered: