-
public class FfiResource
-
-
Method Summary
Modifier and Type Method Description static intretain(AutoCloseable o)Provides a method for another language to express a desire to retain a Java objectwhile in use across an FFI boundary. static intrelease(AutoCloseable o)Release an object that has previously been retained. -
-
Method Detail
-
retain
static int retain(AutoCloseable o)
Provides a method for another language to express a desire to retain a Java objectwhile in use across an FFI boundary. This is required because the Java GC has noway 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 isinitialised 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 thereference count later drops to zero. If the same object is also kept on the Java side itmust be retained so that it does not get unexpectedly closed when the FFI finishes with it.
- Parameters:
o- The resource to retain
-
release
static int release(AutoCloseable o)
Release an object that has previously been retained. If the reference count decrements tozero, the strong reference to that object will be removed and
{@code close()}will be called.- Parameters:
o- The resource to release
-
-
-
-