问题
When Ehcache is used for hibernate second level cache, do the objects in echache get garbage collected by the JVM?
回答1:
They will eventually get garbage collected...
But given you say "the objects in ehcache", I'd be tempted to say... it depends. i.e. for as long as Ehcache deems the data "valuable" and you only have on-heap storage configured, it'll remain on heap. Depending on the version you run and the cache's topology, when not considered "hot" enough anymore to remain on-heap (i.e. as close as possible to your application's code), ehcache will either send the entry to another tier (offheap, disk) or just dispose of it (while it could also already be present elsewhere: offheap, disk, TSA; and as such remain available through the Cache's API, while not being on-heap anymore), making it eligible for GC'ing.
来源:https://stackoverflow.com/questions/24346428/garbage-collection-when-ehcache-is-used-for-hibernate-second-level-cache