How to enhance the soft references JVM memory usage efficiency and weak references?

Reference types: strong references (new), false references, soft references, weak references
1. soft references (SoftReference)
If an object has only soft references, and the current virtual machine stack memory enough, then the garbage collector does not reclaim it, On the contrary it will recover these objects soft reference points.
2. Weak references (WeakReference) with reference to the difference between the soft
garbage collector once found on a piece of memory only weak references, regardless of the current memory is not enough, we will recover this memory.
2. Soft reference / references to improve memory performance weak
1) when sufficient memory, without using soft references.
2) enhance the efficiency of caching
to go to cache query, the query to return; not query, the query to the database, will acquire the contents stored in the cache, return.
eg: soft references / weak references do cache
3) Why not make a strong reference to the cache
strong references can not be recycled

Guess you like

Origin blog.51cto.com/13678728/2475476