Class JNIReference


  • public final class JNIReference
    extends java.lang.ref.WeakReference<java.lang.Object>
    Returned by IBuffer.getByteBuffer(int, int, java.util.concurrent.atomic.AtomicReference) for users that want to explicitly manage when the returned ByteBuffer is released.

    This class creates a WeakReference that Ferry classes will use for memory management. We do this to avoid relying on Java's finalizer thread to keep up and instead make every new native allocation first release any unreachable objects.

    Most times these objects are managed behind the scenes when you call RefCounted.delete(). But when we return ByteBuffer objects, there is no equivalent of delete(), so this object can be used if you want to explicitly control when the ByteBuffer's underlying native memory is freed.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void delete()
      Explicitly deletes the underlying native storage used by the object this object references.
      java.lang.String toString()
      Creates a string representation of this reference.
      • Methods inherited from class java.lang.ref.Reference

        clear, clone, enqueue, get, isEnqueued, reachabilityFence
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • delete

        public void delete()
        Explicitly deletes the underlying native storage used by the object this object references. The underlying native object is now no long valid, and attempts to use it could cause unspecified behavior.
      • toString

        public java.lang.String toString()
        Creates a string representation of this reference. If the underlying object this reference points to has been deleted, then "native" will be zero. If JNIMemoryManager.isMemoryDebugging() is true, then the class and hashcode of the object this reference points to (or used to point to) is also printed.

        If the reference still points to an actual object, we will also print the contents of that object. It may return "null" in which case the underlying object is no longer reachable, but if native != 0, it means it has not yet been collected by Ferry.

        Overrides:
        toString in class java.lang.Object