{
JNIEnv* env = getJNIEnv();
// JavaInstance creates a global ref to instance in its constructor.
- env->DeleteGlobalRef(_instance->instance());
+ env->DeleteGlobalRef(m_instance->instance());
- // Set the object to our WeakReference wrapper.
- m_instance->setInstance(adoptGlobalRef(env, instance));
+ // Set the object to a weak reference.
- _instance->setInstance(env->NewWeakGlobalRef(instance));
++ m_instance->setInstance(env->NewWeakGlobalRef(instance));
+ }
+ ~WeakJavaInstance()
+ {
+ JNIEnv* env = getJNIEnv();
+ // Store the weak reference so we can delete it later.
- jweak weak = _instance->instance();
++ jweak weak = m_instance->instance();
+ // The JavaInstance destructor attempts to delete the global ref stored
- // in _instance. Since we replaced it in our constructor with a weak
++ // in m_instance. Since we replaced it in our constructor with a weak
+ // reference, restore the global ref here so the vm will not complain.
- _instance->setInstance(env->NewGlobalRef(
- getRealObject(env, _instance->instance()).get()));
++ m_instance->setInstance(env->NewGlobalRef(
++ getRealObject(env, m_instance->instance()).get()));
+ // Delete the weak reference.
+ env->DeleteWeakGlobalRef(weak);
}
virtual void virtualBegin()