SoftReference的回收条件
当gc执行时,决定SoftReference回收有两个因素:
SoftReference的timestamp有多少空闲空间
在server模式下,会用-Xmx参数得到空闲空间大小。
在client模式下,会用当前heap最大空闲空间大小。
简单来说,server模式下会优先扩大heap大小,client模式下会优先回收垃圾。
SoftReference类中,有一个timestamp:
public class SoftReference<T> extends Reference<T> { /* Timestamp clock, updated by the garbage collector */ static private long clock; /* Timestamp updated by each invocation of the get method. The VM may use * this field when selecting soft references to be cleared, but it is not * required to do so. */ private long timestamp; ......}