3

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))
                        }
                    }
Renattele Renattele
  • 1,626
  • 2
  • 15
  • 32
  • Have you tried running release version with r8 optimizations? If you can reproduce it with such a simple code, I suggest you [reporting it](https://issuetracker.google.com/issues/new?component=612128). Don't forget to mention used compose version, perfectly upload a sample project to reproduce the problem. – Phil Dukhov May 13 '22 at 09:50
  • Some thoughts after Google IO 2022: try to use "Key" parameter - items(count: Int, key: ((index: Int) -> Any)? = null) – brucemax May 13 '22 at 22:57
  • @PylypDukhov yes, certainly, i use r8 optimizations. Also reported this bug – Renattele Renattele May 14 '22 at 05:17
  • 1
    @brucemax unfortunately, keys didn't stop memory leaks. – Renattele Renattele May 14 '22 at 05:33
  • LazyVerticalGrid is still unstable at this moment, you better use LazyColumn with Row inside of it – uragiristereo May 14 '22 at 08:57

1 Answers1

1

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.

Jakub Minařík
  • 196
  • 1
  • 6