Hello everyone. In according to documentation we must to cancel a scope when we do not need more of it.
Copy code
class MyAndroidActivity {
private val scope = MainScope()
override fun onDestroy() {
super.onDestroy()
scope.cancel()
}
}
Out of curiosity, what happen if I do not call cancel on onDestroy()??
k
kevin.cianfarini
05/17/2024, 3:17 PM
You would potentially leak concurrently running coroutines rather than cleaning them up.
f
Francis Mariano
05/17/2024, 3:18 PM
Even If the application is closed??
k
kevin.cianfarini
05/17/2024, 3:19 PM
if the process is killed, then your concurrent tasks would be killed as well. But if your activity is killed but your app process is still alive you’d leak concurrent takss