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

ermac10k

07/06/2021, 1:04 PM
Hello! if i have a coroutine task and i call a join on it
task.join()
and this join never returns than i do have a memory leak, don’t i?
c

cjmartinkoski

07/06/2021, 4:58 PM
if this coroutine could take too long to reply, you can use
withTimeout
to define a limit
n

Nick Allen

07/06/2021, 8:11 PM
You may or may not have a memory leak. To the garbage collector, coroutines are just objects, and they get cleaned up too if nothing is referring to them. The coroutine waiting for join will hang on to references it needs for resume, but if the coroutine isn't referenced (specifically the continuation) then it could all get GC'd. So it really depends. I'd be more concerned from a design perspective about a join that never returns, sounds suspicious.
🙏 1
c

CLOVIS

07/07/2021, 11:16 AM
Join in coroutines doesn't do memory management (unlike pthread_join, if that's why you're asking). Launching & joining or launching and not joining doesn't make a difference, because the GC handles memory in all cases. So not having a join is not a memory leak in itself, but as the others have said it depends what else you're doing. If you want you can send a more detailed example of what you're doing so we can help with the details
4 Views