Android & Jetpack Compose (50 Qs)•Part 3: ART Internals, Memory Leak Profiling & Production Hardening (25 - 35)
Jetpack Compose State Stability: `@Stable`, `@Immutable`, and Collections stability.
senior LevelPerformanceMemory ManagementDocker & Containers
In Simple Words: In Compose, a function can only be skipped during recomposition if all its parameters are proven to be Stable:
- Primitives & Strings: Automatically stable.
- The List Problem: Standard Kotlin
List<T>is an interface. Because a mutableArrayListcan be passed as aList, the Compose compiler treats standard collections as Unstable, causing views to needlessly recompose on every frame! - Fixes:
- Use Kotlinx Immutable Collections (
ImmutableList<T>). - Annotate custom UI data models with
@Immutableor@Stable. - Pass lambdas as method references or wrap in
remember.
- Use Kotlinx Immutable Collections (