Ways to improve the efficiency of JVM memory use through soft references and weak references
Reference types: new, virtual reference, soft reference, weak reference
1. Soft reference (SoftReference)
If an object has only soft references and the current virtual machine stack has enough memory, the garbage collector will not reclaim it; instead, it will reclaim the objects to which these soft references point.
two。 The difference between WeakReference and soft reference
Once the garbage collector finds that there are only weak references on a block of memory, it will reclaim the memory regardless of whether the current memory space is sufficient or not.
two。 Improve memory performance through soft / weak references
1) when there is enough memory, there is no need to use soft references.
2) improve efficiency with cache
First go to the cache to query, query to return; if the query is not available, go to the database to query, store the acquired content in the cache, and return.
Eg: soft reference / weak reference caching
3) Why not use strong references for caching
Strong references cannot be recycled