From b84fd63fb053dccab0406dbc284702d1ec5886ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Kosmaty?= Date: Tue, 12 Nov 2024 16:39:16 +0100 Subject: [PATCH] fix: Remove dangling global reference to `ScreenModule` (#2494) ## Description Removes a dangling global reference to the `ScreenModule`. ## Changes When the application reloads, `nativeInstall` is called, which overwrites the reference to `globalThis` without deleting it. This PR deletes the reference before creating a new one. ## Test code and steps to reproduce I've tested it in a new project created using expo (SDK 52) and with fabric turn on. --- android/src/main/cpp/jni-adapter.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/android/src/main/cpp/jni-adapter.cpp b/android/src/main/cpp/jni-adapter.cpp index a9632e4dc2..70fd7f1d4c 100644 --- a/android/src/main/cpp/jni-adapter.cpp +++ b/android/src/main/cpp/jni-adapter.cpp @@ -18,6 +18,9 @@ Java_com_swmansion_rnscreens_ScreensModule_nativeInstall( return; } jsi::Runtime &rt = *runtime; + if (globalThis) { + env->DeleteGlobalRef(globalThis); + } globalThis = env->NewGlobalRef(thiz); JavaVM *jvm; env->GetJavaVM(&jvm);