I am writing some code where I might need to create an unbounded number of future objects (java.util.concurrent.Future).
But I am worried about running out of memory at some point.
Couple of questions here:
- Does the jvm know that once the future has completed, it is not being refernced anywhere and therefore is eligible for GC (even if the thread within which it was created is still alive and running)?
- Ideally, I wouldn't want to keep track of these futures themselves. But if I do keep the reference of these futures and periodically call cancel on them, will that make them available for GC?