RFR (S) CR 6857566: (bf) DirectByteBuffer garbage creation can outpace reclamation

Peter Levart peter.levart at gmail.com
Wed Oct 2 17:15:41 UTC 2013


On 10/02/2013 06:31 PM, Alan Bateman wrote:
> One thing that I'd like to understand is the implication of moving 
> from phantom to weak references.

I think Cleaners as WeakReferences are not correct.

Imagine the following code:

         Reference<ByteBuffer> refBb;
         {
             ByteBuffer dbb = ByteBuffer.allocateDirect(1000);
             refBb = new SoftReference<>(dbb);
         }
         System.gc(); // can clear Cleaners, might already process them


         ByteBuffer dbb = refBb.get(); // whoops!


...you could get a reference to direct ByteBuffer after the cleaner has 
already deallocated it's native memory block...

Back to PhantomReference, I think.

Peter



More information about the core-libs-dev mailing list