ditto-lib / live.ditto.ffi / FfiResource

FfiResource

open class FfiResource

Functions

release

open static fun release(o: AutoCloseable!): Int

Release an object that has previously been retained. If the reference count decrements to zero, the strong reference to that object will be removed and close() will be called.

retain

open static fun retain(o: AutoCloseable!): Int

Provides a method for another language to express a desire to retain a Java object while in use across an FFI boundary. This is required because the Java GC has no way to know if another language is holding an opaque reference to a Java pointer. If this object has not yet been retained, a strong reference is kept and the count is initialised to 1. If the same instance has previously been retained the count will be atomically incremented. Retained objects must be AutoCloseable so they can be cleaned up predictably when the reference count later drops to zero. If the same object is also kept on the Java side it must be retained so that it does not get unexpectedly closed when the FFI finishes with it.