Status Update
Comments
so...@google.com <so...@google.com>
rh...@gmail.com <rh...@gmail.com> #2
First of all thanks for this detailed issue.
This issue had been investigated thoroughly when it was first reported internally. The surprising detail in this report is that the issue is not reproducible before 1.7
. I will look into this.
The main problem with POBox is the fact that it is deprecated. Since 2021 Sony has been shipping new Xperia devices with Gboard pre-installed. Although we are aware that there is still a considerable amount of users still using POBox, the described behavior is caused by POBox's noncompliant behavior with InputConnection
and InputMethodManager
documentation. However, this is understandable since TextView
implementation was also not respecting the behavior that is expected from Editors.
Ultimately we have decided to enforce the documented behavior with specifically regards to when editors should call InputMethodManager.updateSelection
. Also, although unconfirmed, there were traces of possible custom code being included in Sony OEM images that changed how InputMethodManager was notified from TextView. If POBox also depended on something like this, it would be impossible for Compose code to replicate the same unknown behavior.
rh...@gmail.com <rh...@gmail.com> #3
Or is that option not available?
Even if the root cause is POBox, from the perspective of the app's customers, it looks like an app bug, so this issue is a blocker against updating Jetpack Compose.
rh...@gmail.com <rh...@gmail.com> #4
Just to be sure, it is dangerous to replace Compose TextField with Android View EditText as a workaround for this issue.
Compose 1.7 has a bug that causes ANR when the focus is on EditText.
Another View-related bug in Compose 1.7 is that an Android View is focused by calling FocusManager.clearFocus().
Perhaps there is a lack of testing of Compose 1.7 in combination with Android View. There is also a possibility that there are other fatal bugs related to View.
In other words, the only options for apps targeting the Japanese market that require POBox support are to continue using Compose 1.6 or to use EditText in combination with various workarounds.
an...@google.com <an...@google.com>
se...@gmail.com <se...@gmail.com> #5
Project: platform/frameworks/support
Branch: androidx-main
Author: Halil Ozercan <
Link:
Fix POBox keyboard issue
Expand for full commit details
Fix POBox keyboard issue
Fix: 373743376
Fix: 329209241
Test: NullableInputConnectionWrapperTest
Change-Id: I94e0e598274fb88b255f977f9fbd50dfbbb1ecb1
Files:
- M
compose/ui/ui/src/androidInstrumentedTest/kotlin/androidx/compose/ui/text/input/NullableInputConnectionWrapperTest.kt
- M
compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/text/input/NullableInputConnectionWrapper.android.kt
Hash: 57f58c4b80d5d8470b2aca325dfdcd55f235231e
Date: Thu Oct 24 01:25:20 2024
[Deleted User] <[Deleted User]> #6
Many thanks again for this report. Especially for giving us a huge clue in terms of what could be going wrong. The fix is now merged and I will ask for a cherry-pick into a stable release.
se...@gmail.com <se...@gmail.com> #7
Do you have any concrete plan to cherry-pick the fix into current stable version (1.7.x)? We are currently waiting it.
se...@gmail.com <se...@gmail.com> #8
Yes, this fix is planned to be included in a future 1.7.x
release.
lu...@perrystreet.com <lu...@perrystreet.com> #9
Thanks for the fix. Sorry to follow up on this. is it possible for you to share specific release version/date for the stable version? We are waiting on this to decide on our direction.
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: