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

Reply via email to