SoftReferences and java.lang.OutOfMemoryError: Direct buffer memory

Brett Okken brett.okken.os at gmail.com
Tue Dec 15 02:22:36 UTC 2020


 I am not sure if this is the correct mailing list for this question.
Please let me know if I should post it somewhere else.

The javadoc for SoftReference states:

All soft references to softly-reachable objects are guaranteed to have been
cleared before the virtual machine throws an OutOfMemoryError.

But that is not quite true when it comes to allocating direct ByteBuffer
instances. Would it be possible to clear softly-reachable direct ByteBuffer
instances prior to throwing java.lang.OutOfMemoryError: Direct buffer
memory? This would make it much simpler (and safer) to implement a cache of
direct ByteBuffer instances for re-use.

Brett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20201214/984ec520/attachment.htm>


More information about the nio-dev mailing list