Skip to content

Can onRemoval() happen after the cache is GC eligible? #955

Answered by ben-manes
chriskessel asked this question in Q&A
Discussion options

You must be logged in to vote

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.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@ben-manes
Comment options

@chriskessel
Comment options

@ben-manes
Comment options

@chriskessel
Comment options

Answer selected by ben-manes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants