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

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

Open
Jaehwa-Noh opened this issue Nov 17, 2024 · 0 comments
Open

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

Jaehwa-Noh opened this issue Nov 17, 2024 · 0 comments

Comments

@Jaehwa-Noh
Copy link

I just notice lifeCycleOwner passed to viewModel function.

fun startPreview(
lifecycleOwner: LifecycleOwner,
surfaceProvider: Preview.SurfaceProvider,
captureMode: CaptureMode,
cameraSelector: CameraSelector,
rotation: Int,
) {

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant