Can onRemoval() happen after the cache is GC eligible? #955
-
I have no idea if this could happen, so mostly I'm curious how this works.
What happens with the old cache and expiring entries in it now that it's no longer referenced? It's GC eligible, but that might not happen immediately. Could entries in this GC eligible cache age out and cause the onRemoval() event to fire? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
It should not, but I could imagine some races that could allow a surprise. The cache does not create any threads itself and by default will only expire entries as a side effect of other read/write operations. If you have a |
Beta Was this translation helpful? Give feedback.
It should not, but I could imagine some races that could allow a surprise.
The cache does not create any threads itself and by default will only expire entries as a side effect of other read/write operations. If you have a
scheduler
set, then that thread will use the next expiration time to trigger a maintenance cycle. That scheduled task weakly holds the cache and will no-op if absent. If the reference was not collected then it might allow for a new strong reference and resurrect it (that is a GC implementation detail). In this case if the gc did not collect and the reference was not cleared, then maybe it could happen.