Is it okay to pass `lifeCycleOwner` to viewModel function?
- Dominant language
- Kotlin
- Stars
- 721
- Forks
- 162
- PR merge metrics
- No merged PRs in 30d
Description
I just notice `lifeCycleOwner` passed to viewModel function.
https://github.com/android/socialite/blob/67d823a1ecf9e615765bda894ccc83133c1b6427/app/src/main/java/com/google/android/samples/socialite/ui/camera/CameraViewModel.kt#L142-L148
But in the ViewModel documentation, that gives a caution that situation.
https://developer.android.com/topic/libraries/architecture/viewmodel#implement-viewmodel
> Caution: A [ViewModel](https://developer.android.com/reference/androidx/lifecycle/ViewModel) usually shouldn't reference a view, [Lifecycle](https://developer.android.com/reference/androidx/lifecycle/Lifecycle), or any class that may hold a reference to the activity context. Because the ViewModel lifecycle is larger than the UI's, holding a lifecycle-related API in the ViewModel could cause memory leaks.
Is it supposed should be refactoring that related code?
Contributor guide
Research direction
Start with app/src/main/java/com/google/android/samples/socialite/ui/camera/CameraViewModel.kt at lines 142-148 and compare the lifecycleOwner usage with the linked ViewModel documentation. Determine whether that reference should be removed or restructured, then verify that the camera ViewModel still behaves correctly without risking a lifecycle-related leak.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100