androidandroid-jetpack-composeandroid-jetpack-compose-listjava-memory-leaks

LazyList memory leak in Jetpack Compose


I found out that LazyList generates memory leaks. When I scroll down to the bottom of the list memory usage by my app increases by ~3MB. After I scroll up and usage also increases by ~3MB. Memory usage increases all the time is scroll list. How to fix it? Issue on Google IssueTracker

P.S. Sometimes memory usage drops down by 50-100mb. In my test project(code below) usage grows up to 150mb. In my other, more complex projects it grows up to 200-250mb. In a theory it can cause OutOfMemoryException.

Example:

LazyVerticalGrid(columns = GridCells.Fixed(2)) {
                        item(span = { GridItemSpan(2) }) {
                            LargeTopAppBar(title = {
                                Text(text = "Explore new")
                            })
                        }
                        items(50) {
                            Box(modifier = Modifier
                                .fillMaxWidth()
                                .height(250.dp))
                        }
                    }

Solution

  • This issue is already reported and as of now still not resolved.

    In a theory it can cause OutOfMemoryException.

    Not only in theory as we recently had to downgrade a production version of an app back to Compose 1.1.1 due to this exact issue. As far as I know this is the only possible solution for now.

    I guess we should stick to stable versions of Compose from now on.