-
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
onClick lambda will leak refrences. #538
Comments
Not sure if this is what typically called "leak". That's how generally value capturing works. If certain object is used in lambda - its reference is held by lambda object. Probably slight rework on state management with more granular state objects may help. |
Thanks for your comment @olonho . Passing the reference and holding it in the lambda is ok and is exactly what I want. After calling GC manually or even waiting a long time (for automatic GC to happen) all of the other useless objects were removed from the heap except this one.
|
Thanks! I checked this code:
And indeed, we have a memory leak. And probably we already have a solution. Will try it |
@igordmn Thanks for the complete example. I should have pasted my example completely too, sorry. |
@worldsnas Try https://issuetracker.google.com/issues/170869626#comment4 |
…posed. Fixes JetBrains/compose-multiplatform#538 and https://partnerissuetracker.corp.google.com/issues/170869626#comment4 As far as I figure out how observation works, it is enough to call `clearInvalidObservations` in the end of the every frame. Because all changes will be commited before (on recomposition/layout/draw). Similar code is in https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/AndroidComposeView.android.kt;l=378;drc=f3b4f4f28cf61d4434af59d9247a9d2f6d5d70e7. Bug: 183493610 Test: JetBrains/compose-multiplatform#538 (comment), click "Next" multiple times, run VisualVM, run GC, dump heap, find "Presenter" Test: ./gradlew jvmTest desktopTest -Pandroidx.compose.multiplatformEnabled=true Change-Id: I864f4e7aeca28547465ea468229e19426d7b2827
Shall be fixed with 0.4.0-build179. |
JetBrains#538) * Add test reproducing reported user story. Implement fix. Document edge case bug. * Update compose/material/material/src/commonMain/kotlin/androidx/compose/material/Slider.kt Co-authored-by: Ivan Matkov <[email protected]> * Update compose/material/material/src/commonMain/kotlin/androidx/compose/material/Slider.kt Co-authored-by: Ivan Matkov <[email protected]> * Revert "Update compose/material/material/src/commonMain/kotlin/androidx/compose/material/Slider.kt" This reverts commit b3fd5cc7a6b668ecd2ee9ebe7864eb0e5c71b586. --------- Co-authored-by: Elijah Semyonov <[email protected]> Co-authored-by: Ivan Matkov <[email protected]>
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks. |
If any reference is used in the
onClick
lambdas the reference will be leaked and won't be garbage collected.that applies to both:
Modifier.clickable{}
andButton(onClick= {})
here is a small sample to showcase this issue:
In here the presenter object will be leak just because it's been referenced in the
onClick
lambda. there is the object graph which leads to: rootRecomposer
,AppManager
andawt.Window
summary of heap graph by JProfiler: (Jprofiler noob here sorry if I couldn't export it any better way!)
The text was updated successfully, but these errors were encountered: