android / socialite

Apache License 2.0
406 stars 74 forks source link

Is it okay to pass `lifeCycleOwner` to viewModel function? #108

Open Jaehwa-Noh opened 2 weeks ago

Jaehwa-Noh commented 2 weeks ago

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 usually shouldn't reference a view, 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?