https://kotlinlang.org logo
#coroutines
Title
# coroutines
m

Maciek

04/18/2020, 10:53 AM
should I care about closing/cancelling channel during object teardown if it's used only internally in the object and coroutine scope to operate it was already cancelled?
🚫 1
f

fatih

04/18/2020, 10:54 AM
Since the coroutine which is using to operate that is also cancelled and you are sure that that channel is no longer being used, I think you don't need to care about it
👍 1
e

Erik

04/18/2020, 4:32 PM
Channels are a communication primitive between coroutines, but need not to be closed if the coroutines are no longer active. Closing a channel is useful for other things, but is not necessary in your case.
👍 1
Also, see this answer by Roman Elizarov: https://stackoverflow.com/a/43889107/3169029 Quote:
Channels are not tied to any native resource and they don't have to be closed to release their memory. Simply dropping all the references to a channel is fine. GC will come to do clean it up.
👍 3
3 Views