Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Compose-related memory leaks #1446

Open
3 tasks done
brian-livefront opened this issue May 16, 2024 · 2 comments
Open
3 tasks done

[Bug]: Compose-related memory leaks #1446

brian-livefront opened this issue May 16, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@brian-livefront
Copy link

brian-livefront commented May 16, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Is there a StackOverflow question about this issue?

  • 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.

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

  • I agree to follow this project's Code of Conduct
@brian-livefront brian-livefront added the bug Something isn't working label May 16, 2024
@dturner dturner self-assigned this Jul 2, 2024
@sl-ahmedabdellaoui
Copy link

Hello,

I have encountered the same issue with TopicViewModel. Here are the steps to reproduce it:

  • Navigate to Interests.
  • Open one Topic.
  • Go back to Interests.
  • Return to the Home screen.
  • Open a profiler, record a dump, and search for TopicViewModel.

You'll notice that TopicViewModel is still present. The memory leak appears to be related to a lambda function referencing the ViewModel. Upon further inspection, it seems the ViewModel is retained by the AccessibilityManager as shown below:

Capture d’écran 2024-07-26 à 16 08 12

Is there any update on this issue ?

By the way, even in another Android app using Compose, I noticed the same behavior. ViewModels seem to be kept in memory even after onCleared is called.
thank you

@carterinchina
Copy link

yes I have encountered the same issue too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants