enighma
10/29/2024, 8:56 PMappscope
and I'm using that to collect a private stateflow in a class as shown below.
Do I risk leaking something when this class is garbage collected? I.e. do I need clean up the launch?
private val flowA = StateFlow()
init {
appscope.launch {
flowA.collect{}
}
}
fun update() {
flowA.value = x
}
leandro
10/30/2024, 10:13 AMSam
10/30/2024, 3:43 PMStateFlow
never terminates, so that collect()
call will run forever. That means the coroutine will stick around until you cancel its scope. That leaves you, at a minimum, with a leaked reference to flowA
and its latest value
.leandro
10/30/2024, 3:46 PMcollect()
to pipe something to somewhere intending to keep these in sync while the app "exists", that would be okay, or?Sam
10/30/2024, 3:49 PMSam
10/30/2024, 3:51 PMenighma
10/30/2024, 11:44 PM