1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Fix leakage of JNI object references

Fixes https://github.com/godotengine/godot/issues/87548
This commit is contained in:
Fredia Huya-Kouadio
2024-04-15 10:30:18 -07:00
parent b8fa48be04
commit f291a4ed3a
20 changed files with 139 additions and 32 deletions

View File

@@ -209,8 +209,6 @@ class JavaClassWrapper : public Object {
#ifdef ANDROID_ENABLED
RBMap<String, Ref<JavaClass>> class_cache;
friend class JavaClass;
jclass activityClass;
jmethodID findClass;
jmethodID getDeclaredMethods;
jmethodID getFields;
jmethodID getParameterTypes;
@@ -229,7 +227,6 @@ class JavaClassWrapper : public Object {
jmethodID Long_longValue;
jmethodID Float_floatValue;
jmethodID Double_doubleValue;
jobject classLoader;
bool _get_type_sig(JNIEnv *env, jobject obj, uint32_t &sig, String &strsig);
#endif

View File

@@ -239,6 +239,17 @@ public:
JNISingleton() {
#ifdef ANDROID_ENABLED
instance = nullptr;
#endif
}
~JNISingleton() {
#ifdef ANDROID_ENABLED
if (instance) {
JNIEnv *env = get_jni_env();
ERR_FAIL_NULL(env);
env->DeleteGlobalRef(instance);
}
#endif
}
};