-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Detecting ViewModel leaks? #1731
Labels
Milestone
Comments
pyricau
added a commit
that referenced
this issue
Jan 30, 2020
AndroidXFragmentDestroyWatcher adds a spy view model in every ViewModelStoreOwner instance (ie FragmentActivity and Fragment). ViewModelClearedWatcher is a view model that holds on to the map of view models backing its store. When ViewModelClearedWatcher receives the onCleared() callback, it adds each live view model from the store to the ObjectWatcher. Other changes: * Renamed FragmentLeakTest to LifecycleLeaksTest. * Added tests for activity leaks and view model leaks. * Refactored leak tests for readability. Fixes #1731
pyricau
added a commit
that referenced
this issue
Jan 30, 2020
AndroidXFragmentDestroyWatcher adds a spy view model in every ViewModelStoreOwner instance (ie FragmentActivity and Fragment). ViewModelClearedWatcher is a view model that holds on to the map of view models backing its store. When ViewModelClearedWatcher receives the onCleared() callback, it adds each live view model from the store to the ObjectWatcher. Other changes: * Renamed FragmentLeakTest to LifecycleLeaksTest. * Added tests for activity leaks and view model leaks. * Refactored leak tests for readability. Fixes #1731
pyricau
added a commit
that referenced
this issue
Jan 30, 2020
AndroidXFragmentDestroyWatcher adds a spy view model in every ViewModelStoreOwner instance (ie FragmentActivity and Fragment). ViewModelClearedWatcher is a view model that holds on to the map of view models backing its store. When ViewModelClearedWatcher receives the onCleared() callback, it adds each live view model from the store to the ObjectWatcher. Other changes: * Renamed FragmentLeakTest to LifecycleLeaksTest. * Added tests for activity leaks and view model leaks. * Refactored leak tests for readability. Fixes #1731
Does this work when view models are loaded inside Compose? Can't seem to find anything on this in the docs. We can manually create a leak at the Activity (Single Activity since it's a full Compose App) and the leak is detected in our tests. However, when creating a leak in a view model the tests do not detect it. |
Opened this issue: #2678 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ViewModels have a lifecycle (they get "cleared), so I wonder if we can automate the detection of view models leaking or at least provide some utilities.
The text was updated successfully, but these errors were encountered: