pub struct GlobalRef { /* private fields */ }
Expand description

A global JVM reference. These are “pinned” by the garbage collector and are guaranteed to not get collected until released. Thus, this is allowed to outlive the JNIEnv that it came from and can be used in other threads.

GlobalRef can be cloned to use the same global reference in different contexts. If you want to create yet another global ref to the same java object you may call JNIEnv#new_global_ref just like you do when create GlobalRef from a local reference.

Underlying global reference will be dropped, when the last instance of GlobalRef leaves its scope.

It is recommended that a native thread that drops the global reference is attached to the Java thread (i.e., has an instance of JNIEnv). If the native thread is not attached, the GlobalRef#drop will print a warning and implicitly attach and detach it, which significantly affects performance.

Implementations

Get the object from the global ref

This borrows the ref and prevents it from being dropped as long as the JObject sticks around.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

This conversion assumes that the GlobalRef is a pointer to a class object.

Look up the concrete type from the JVM.

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.