SoftReference incorrect javadoc?
Michael Pollmeier
michael at michaelpollmeier.com
Tue Apr 16 02:14:46 UTC 2019
Quoting
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ref/SoftReference.html
> All soft references to softly-reachable objects are guaranteed to have
been cleared before the virtual machine throws an OutOfMemoryError
That statement was true when soft references were first introduced in
java 1.2, but from java 1.3.1 the jvm property
`-XX:SoftRefLRUPolicyMSPerMB` was introduced.
It defaults to 1000 (milliseconds), meaning that if there’s only 10MB
available heap, the garbage collector will free references that have
been used more than 10s ago. I.e. everything else (including young
softly reachable objects) will *not* be freed, leading to an
OutOfMemoryError, contradicting the above quoted 'guarantee'.
That's also the behaviour I observed on various JREs. Would you agree,
i.e. should I propose an updated doc?
Cheers
Michael
More information about the jdk-dev
mailing list