use std::mem;
use objects::JObject;
use JNIEnv;
pub struct AutoLocal<'a> {
obj: JObject<'a>,
env: &'a JNIEnv<'a>,
}
impl<'a> AutoLocal<'a> {
pub fn new(env: &'a JNIEnv<'a>, obj: JObject<'a>) -> Self {
AutoLocal { obj: obj, env: env }
}
pub fn forget(self) -> JObject<'a> {
let obj = self.obj;
mem::forget(self);
obj
}
pub fn as_obj<'b>(&'b self) -> JObject<'b>
where
'a: 'b,
{
self.obj
}
}
impl<'a> Drop for AutoLocal<'a> {
fn drop(&mut self) {
let res = self.env.delete_local_ref(self.obj);
match res {
Ok(()) => {}
Err(e) => debug!("error dropping global ref: {:#?}", e),
}
}
}