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

ansman

04/27/2019, 3:12 PM
Do I need to keep a strong reference to a continuation given to me in
suspendCancellableCoroutine
? I need to work around a memory leak and I was planning on doing that by keeping a weak ref to the continuation
d

Dominaezzz

04/27/2019, 3:14 PM
You can but you must be able to call
resume
on it at some point.
a

ansman

04/27/2019, 3:15 PM
Well, I can’t guarantee that either which is why I also have a
withTimeout
around it
l

louiscad

04/27/2019, 5:51 PM
You are likely to get your coroutine garbage collected while suspended if you use a weak reference on it
a

ansman

04/27/2019, 5:52 PM
Hmm, so I need to keep a strong reference?
b

bdawg.io

04/27/2019, 5:53 PM
You should keep a strong reference to things you don’t want garbage collected.
1
a

ansman

04/27/2019, 6:00 PM
I know that… but I was hoping that the parent job would keep a strong ref so I didn’t have to
Actually I can’t find any reference to a job only keeping a weak ref to child jobs
7 Views