I'm not sure what your expectations are for "starting and stopping a custom ViewModel manually" -- but a ViewModel should always be scoped to the ViewModelStore and should only be cleared when the ViewModelStore is cleared. You shouldn't be trying to manually control that; and if Koin allows that I would really recommend against.
If you want control over the lifetime of the ViewModel instance, you probably don't need ViewModels. Create a custom scope, a custom class and handle the lifetime of that class instance yourself.
Marcello Galhardo
08/01/2024, 12:03 AM
I double checked Koin's docs, and it seems the ScopeViewModel does respect the ViewModel lifetime:
> All instances inside a ViewModel scope have the same visibility and will survive for lifetime of ViewModel instance, until ViewModel's onCleared function is called
>
If my understanding is correct, the ScopeViewModel will be cleared only when the ViewModelStore is cleared (expected behaviour).
Reference: https://insert-koin.io/docs/reference/koin-android/scope/#viewmodel-scope-since-354