- 软引用soft reference,内存不足时回收
- 用来实现内存敏感的高速缓存, 如object-cache,为了能cache又不会内存不足
- SoftReference
softRef = new SoftReference (s) - 回收
- 将softRef引用referent(s)设为null,不再引用new String("")
- new String("")设置为可结束(finalizable)
- new String("")运行finalize(),空间释放。softRef添加到它的ReferenceQueue(如果有)
-
设置-Xms20M -Xmx20M SoftReference<byte[]> m = new SoftReference<>(new byte[1024*1024*10]); System.gc(); m.get(); new byte[1024*1024*15] m.get();