Trying to understand how LazyList works under the ...
# compose
f
Trying to understand how LazyList works under the hood but it’s not that easy. 🤔 Is there anyone knows how the recycling works in a LazyColumn? Do items get recomposed or do they just exit the composition and new one are created ? And finally what would be the effect of using
DisposableEffect
inside a composable used by a LazyList in the case the items are reused? 🙏
c
Recycling recycles nodes, not state. Each item create a new composition but the nodes can be reused from a previous item. This means that the
DisposableEffect
for example, will dispose as if no recycling is done at all. When the item is scrolled off and the composition is "recycled", the disposable effects are disposed.
👍 1
c
Wasn't "recycling" added fairly recently to
Lazy*
? Wasn't Lazy* not really recycling, but just creating things just in time, and throwing them away when they went off the screen?
👍 1
m
is that something new related to performance?
a
the main thing you should be aware of is when item is not visible anymore it doesn’t mean it is disposed. it will be kept active for a while until we want to reuse this composition. and only then the DisposableEffect’s onDispose will be triggered
👍 1
so if you need the info about what items are visible use
LazyListState.layoutInfo
m
@Andrey Kulikov so
DisposableEffect.dispose()
is called only before composable, node, displays new item?
a
@Marko Novakovic currently yes. but we can change that behaviour at any point as well if we decide to tweak the reusing logic in the future
👍 2
what is your use case where it is important when exactly onDispose is called?
f
On my side it's because I'm using a pool of Exoplayer objects
But using one exoplayer for each item didn’t change that much the performance
👍 1