Status Update
Comments
so...@google.com <so...@google.com>
rh...@gmail.com <rh...@gmail.com> #2
Branch: androidx-master-dev
commit b90079595f33f58fece04026a97faa0d243acdb1
Author: Yuichi Araki <yaraki@google.com>
Date: Wed Sep 18 16:55:49 2019
Change the way to detect mismatch between POJO and query
This fixes cursor mismatch warnings with expandProjection.
Bug: 140759491
Test: QueryMethodProcessorTest
Change-Id: I7659002e5e0d1ef60fc1af2a625c0c36da0664d8
M room/compiler/src/main/kotlin/androidx/room/processor/QueryMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
M room/compiler/src/main/kotlin/androidx/room/solver/query/result/PojoRowAdapter.kt
M room/compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
M room/compiler/src/test/kotlin/androidx/room/testing/TestProcessor.kt
rh...@gmail.com <rh...@gmail.com> #3
rh...@gmail.com <rh...@gmail.com> #4
Branch: androidx-master-dev
commit bdde5a1a970ddc9007b28de4aa29d60ffa588f08
Author: Yigit Boyar <yboyar@google.com>
Date: Thu Apr 16 16:47:05 2020
Re-factor how errors are dismissed when query is re-written
This CL changes how we handle errors/warnings if query is
re-written.
There was a bug in expandProjection where we would report warnings
for things that Room already fixes automatically (
The solution to that problem (I7659002e5e0d1ef60fc1af2a625c0c36da0664d8)
solved it by deferring validating of columns until after re-write
decision is made. Unfortunately, this required changing PojoRowAdapter
to have a dummy mapping until it is validating, make it hard to use
as it does have a non-null mapping which is not useful.
This CL partially reverts that change and instead rely on the log
deferring logic we have in Context. This way, we don't need to break
the stability of PojoRowAdapter while still having the ability to
drop warnings that room fixes. This will also play nicer when we
have different query re-writing options that can use more information
about the query results.
Bug: 153387066
Bug: 140759491
Test: existing tests pass
Change-Id: I2ec967c763d33d7a3ff02c1a13c6953b460d1e5f
M room/compiler/src/main/kotlin/androidx/room/log/RLog.kt
M room/compiler/src/main/kotlin/androidx/room/processor/QueryMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
M room/compiler/src/main/kotlin/androidx/room/solver/query/result/PojoRowAdapter.kt
an...@google.com <an...@google.com>
se...@gmail.com <se...@gmail.com> #5
Are there any updates on this issue?
Our app relies on a lot of interop with ComposeView, and this leak has been causing issues and slowing down our integration with Compose.
Any help is much appreciated!
[Deleted User] <[Deleted User]> #6
se...@gmail.com <se...@gmail.com> #7
Do we know if this is fixed in Compose 1.3.0
or 1.3.1
?
Has anyone (or OP) tried repro-ing with those versions yet?
Thanks
se...@gmail.com <se...@gmail.com> #8
FWIW, just tried to repro the leaks with Compose + Compose Compiler 1.3.1
and the leaks seem to have stopped.
Would love confirmation about this being fixed in 1.3.1
just to be sure.
lu...@perrystreet.com <lu...@perrystreet.com> #9
I'm use the latest BOM and the leak still happen. I believe the BOM uses Compose Compiler 1.3.1
.
zh...@gmail.com <zh...@gmail.com> #10
jo...@muzz.com <jo...@muzz.com> #11
Our case:
- Single activity navigating to multiple fragments using a replace transaction
- Each fragment creates a single ComposeView, calling `setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)`
- After navigating back from a fragment (so a fragment is fully destroyed) then leakcanary highlights this leak.
Have also tried manually calling ComposeView.disposeComposition when the view is destroyed but leak still occurs.
lu...@gmail.com <lu...@gmail.com> #12
lu...@gmail.com <lu...@gmail.com> #13
lu...@gmail.com <lu...@gmail.com> #14
See this link
rh...@gmail.com <rh...@gmail.com> #15
I'm not sure lambda functions are the cause here.
At least lambdas we have control over as library users.
The first post has a code example that reproduces the memory leak but there are zero lambdas in use:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(ComposeView(this))
}
}
lu...@gmail.com <lu...@gmail.com> #16
This is my sample: A Simple MainTimer1Activity and a couple of seconds go to MainTimer2Activity
private const val TAG = "MAIN_TIMER_1"
class MainTimer1Activity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyApplicationTheme {
MainTimer1Screen()
}
}
}
}
@Composable
fun MainTimer1Screen() {
Log.e(TAG, "MainTimer1Screen ...")
val ctx = LocalContext.current
LaunchedEffect(key1 = Unit, block = {
try {
startTimer1(5000L) { // start a timer for 5 secs
Log.e(TAG, "Timer ended")
toTimer2Screen(ctx)
}
} catch(ex: Exception) {
Log.e(TAG,"timer cancelled")
}
})
}
suspend fun startTimer1(time: Long, onTimerEnd: () -> Unit) {
delay(timeMillis = time)
onTimerEnd()
}
fun toTimer2Screen(ctx: Context){
val act = ctx.findActivity() as MainTimer1Activity
val intent = Intent(ctx, MainTimer2Activity::class.java)
ctx.startActivity(intent)
act.finish()
}
---------
private const val TAG = "MAIN_TIMER_2"
class MainTimer2Activity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyApplicationTheme {
MainTimer2Screen()
}
}
}
}
@Composable
fun MainTimer2Screen() {
Log.e(TAG, "MainTimer2Screen ...")
val ctx = LocalContext.current
}
---------
The log ourput as espected
MainTimer1Screen ...
Timer ended
MainTimer2Screen ...
So if i look to profiler. and force GC the activitie MainTimer1Activity is removed but still have info about MainTimer1Screen Composable. i dont know if that belong to Composable tree taht never released
in first Capture you see MainTimer1 and Maintimer2 Activities
in Second Capture After force GC many time in 7 minutes. Maintimer2Activity is released. but still there this objects:
ComposableSingletons$Maintiner1Activitykt$lambda-1$1
ComposableSingletons$Maintiner1Activitykt$lambda-2$1
I think this composable are leaked, is strange or there is always info about compsables tree that android never releases
lu...@gmail.com <lu...@gmail.com> #17
fl...@polarsteps.com <fl...@polarsteps.com> #18
So this essentially means that every app out there, which is in any of its activities using ComposeView(s)
will leak those activities. Seems like a P1 to me.
ve...@gmail.com <ve...@gmail.com> #19
Could be related to
There is a small demo project simulating any number of leaks (using fragment and further activities). This is a major issue, which blocking us from releasing many features using compose. They have reproducibility 100%, and have potentially huge impact on memory and performance. Could you please bump this issues to P1?
mo...@gmail.com <mo...@gmail.com> #20
ve...@gmail.com <ve...@gmail.com> #21
From
on 14/02/2023: issue 264389670
Please note that ComposeView is not the prerequisite for this leak, but the changing of the mutable state during hiding of composition in first activity. Although, the root cause could be the same, but this issue doesn't assume any root cause, but provides the setup for replication. Fragment is also not required. I will attach new setup, which does use only just 3 activities. And that's enough for memory leak.
Replication
- From MainActivity go to IntermediateActivity
- From IntermediateActivity go to ComposeActivity
- From ComposeActivity go back
- Checking profiler. Have memory leak
se...@journiapp.com <se...@journiapp.com> #22
ve...@gmail.com <ve...@gmail.com> #23
Any mutable state change during composition hiding is enough for replication. The impact is drastic: all subsequent compose activities are stucking in the memory, and just piling up.
wu...@gmail.com <wu...@gmail.com> #24
lu...@gmail.com <lu...@gmail.com> #25
See $lambda-1$1 in the profiler
ComposableSingletons$Maintiner1Activitykt$lambda-1$1
ComposableSingletons$Maintiner1Activitykt$lambda-2$1
mg...@a-bly.com <mg...@a-bly.com> #26
as...@google.com <as...@google.com> #27
The memory leak is caused by an edge case, when the activity is stopped while Recomposer
is holding some pending state for composition. By default, MonotonicClock
used in Recomposer
is Recomposer
has already queued an update before activity was stopped, and it continues to accumulate states from other activities until the first activity is restarted or destroyed. The issue is quite deeply rooted, as the fix is likely to change how compositions record states in background, so we are targeting next release for the fix.
If you are affected by this issue in the meantime, consider specifying a custom WindowRecomposerFactory
in your app that doesn't pause MonotonicClock
(or unpauses it periodically). The side effect of such custom Recomposer
is that compositions will continue running animations when activity is in background.
ap...@google.com <ap...@google.com> #28
Branch: androidx-main
commit 66fef38b1d11e0c48b11137e6c3d007909f4a2d1
Author: Chuck Jazdzewski <chuckj@google.com>
Date: Wed Mar 29 13:51:01 2023
ON_STOP should pause the frame clock broadcasts instead of composition
When an Android window receives an ON_STOP noficiation it would pause
the pausable clock it created for its recomposer. This has the effect
of pausing all compositions and causes the recomposer to collect change
nofications from the snapshot sustem in an unbounded collection.
With this change, windows that receive ON_STOP will now only pause the
frame clock broadcasts which has the effect of blocking withFrameNanos
that is used by animations. This means animations stop advancing but
composition is allowed to continue allowing the recomposer to drain the
notifications from the snapshot system.
Relnote: """The recomposer created for an Android window will now
only block calls to `withFrameNanos` instead of all composition when it
receives an ON_STOP notification. This means windows associated with
stopped activites will continue to recompose for data changes but the
animations, or any other caller of withFrameNanos, will block."""
Fixes: 240975572
Test: ./gradlew :compose:r:r:tDUT
Change-Id: Id9e7fe262710544a48c2e4fc5fcbf1d27bfaa1ba
M compose/runtime/runtime/api/current.txt
M compose/runtime/runtime/api/public_plus_experimental_current.txt
M compose/runtime/runtime/api/restricted_current.txt
M compose/runtime/runtime/src/commonMain/kotlin/androidx/compose/runtime/Recomposer.kt
M compose/runtime/runtime/src/commonTest/kotlin/androidx/compose/runtime/RecomposerTests.kt
M compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/WindowRecomposer.android.kt
ma...@xapo.com <ma...@xapo.com> #29
This leak is happening for us on every screen migrated to Compose and would like to check any alpha version for the fix.
ch...@google.com <ch...@google.com> #30
This is in android-main
which is now the 1.5 branch. It should be out with the next alpha of 1.5 but not stable until 1.5 is stable.
pr...@google.com <pr...@google.com> #31
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.compose.runtime:runtime:1.5.0-alpha03
androidx.compose.ui:ui:1.5.0-alpha03
lu...@gmail.com <lu...@gmail.com> #32
androidx.compose.runtime:runtime:1.5.0-alpha03
androidx.compose.ui:ui:1.5.0-alpha03
But the problems still exists
ComposableSingletons$Activitykt$lambda-1$1. never are released . The Activity is released. but the composables are always keep it in memory, so its seems to be a kind of memory leak
lu...@gmail.com <lu...@gmail.com> #33
aa...@gmail.com <aa...@gmail.com> #34
How does version 1.4.x handle this bug?
xu...@gmail.com <xu...@gmail.com> #35
[Deleted User] <[Deleted User]> #37
ch...@google.com <ch...@google.com> #38
Lambdas like ComposableSingletons$Maintiner1Activitykt$lambda-1$1
, as the name implies, are lazy allocated singleton instances that are stored globally. They will only be allocated once. This is not addressed by the above fix because it is not a leak but a singlton.
lu...@gmail.com <lu...@gmail.com> #39
lu...@gmail.com <lu...@gmail.com> #40
lu...@gmail.com <lu...@gmail.com> #41
ComposableSingletons$Activitykt$lambda-1$1. that keep in memory
I think is part of the composable framework
Description
Jetpack Compose version: 1.2.0
Android Studio Build: Android Studio Chipmunk | 2021.2.1 Patch 1
Kotlin version: 1.7.0
Steps to Reproduce or Code Sample to Reproduce:
Opening and closing an Activity that uses
ComposeView
causes memory leak. Here's sample code used:LeakCanary points to
Recomposer.snapshotInvalidations
.Stack trace: