[−][src]Struct jni::objects::AutoLocal
Auto-delete wrapper for local refs.
Anything passed to a foreign method is considered a local ref unless it's explicitly turned into a global. These refs are automatically deleted once the foreign method exits, but it's possible that they may reach the JVM-imposed limit before that happens.
This wrapper provides automatic local ref deletion when it goes out of scope.
NOTE: This comes with some potential safety risks. DO NOT use this to wrap something unless you're SURE it won't be used after this wrapper gets dropped. Otherwise, you'll get a nasty JVM crash.
Methods
impl<'a> AutoLocal<'a>
[src]
pub fn new(env: &'a JNIEnv<'a>, obj: JObject<'a>) -> Self
[src]
Creates a new auto-delete wrapper for a local ref.
Once this wrapper goes out of scope, the delete_local_ref
will be
called on the object. While wrapped, the object can be accessed via
the Deref
impl.
pub fn forget(self) -> JObject<'a>
[src]
Forget the wrapper, returning the original object.
This prevents delete_local_ref
from being called when the AutoLocal
gets
dropped. You must either remember to delete the local ref manually, or
be
ok with it getting deleted once the foreign method returns.
pub fn as_obj<'b>(&'b self) -> JObject<'b> where
'a: 'b,
[src]
'a: 'b,
Get a reference to the wrapped object
Unlike forget
, this ensures the wrapper from being dropped while the
returned JObject
is still live.
Trait Implementations
impl<'a, 'b, 'c> Desc<'a, JClass<'b>> for &'b AutoLocal<'c> where
'c: 'b,
[src]
'c: 'b,
This conversion assumes that the AutoLocal
is a pointer to a class object.
impl<'a> Drop for AutoLocal<'a>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,