android / android/nowinandroid

[Bug]: Compose-related memory leaks

Open
#1,446 3 comments 8 reactions 1 assignee Claimed by @dturner View on GitHub
bug
Dominant language
Kotlin
Stars
21.8k
Forks
4.6k
Avg merge
19h 20m
Merged PRs (30d)
2

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is there a StackOverflow question about this issue?

- [X] I have searched StackOverflow

### What happened?

The `SearchViewModel` (and likely other ViewModels) appears to leak after navigating to the search screen and back to the main screen. This seems to be related to [this Compose issue](https://issuetracker.google.com/issues/312895362).

**Steps to reproduce**
- Open the app.
- Navigate to the search screen.
- Enter text in the search field.
- Exit the search screen.
- Open the memory profiler, attempt to force a garbage collection several times, and then collect a heap dump.
- Search for `SearchViewModel` in the heap.

The `SearchViewModel` will still be present in the heap even though the screen was left and many garbage collections were attempted.

Screenshot 2024-05-16 at 12 50 46 PM

### Relevant logcat output

_No response_

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.