I’m converting some code from JDK8 futures to coroutines.
We have an in-memory cache (Caffeine) whose values are CompletableFutures. We keep those futures in the cache for a while after the future is completed. Our understanding is that CompletableFuture has only two references in it (result and stack), and it ensures that after a future is done, the stack is nulled out, so there’s no memory implication to hanging on to the future indefinitely.
I’m considering changing this cache to contain a Deferred. Does Deferred work the same way? It seems like the main Deferred implementation is DeferredCoroutine, which is a AbstractCoroutine, which has plenty of
val references in it.
Will keeping a Deferred around for a while keep lots of objects alive?
If this is a problem, can I fix it just by continuing to store CompletableFutures in the map created by