Use Java WeakRef insteaed of JNI WeakGlobalRef

This prevents a race condition against the garbage collector.