https://kotlinlang.org logo
a

Afzal Najam

10/14/2020, 5:18 PM
Do we need to call
viewModelScope.cancel()
In ViewModels? I see that the documentation for ViewModel.kt says:
* This scope will be canceled when ViewModel will be cleared, i.e [ViewModel.onCleared] is called
But I can't find the code that actually calls
close()
f

flosch

10/14/2020, 5:29 PM
No you do not need to, look into the
viewModelScope
implementation
👍 2
a

Afzal Najam

10/14/2020, 5:33 PM
Ah thanks. I see it now. The getter puts the
viewModelScope
in the
bagOfTags
using
setTagIfAbsent
. And that's closed when
ViewModel.clear()
is called. Great, thanks!
85 Views