From 00af79684d6f4df0d388a14047962f120a031c4c Mon Sep 17 00:00:00 2001 From: Edi Toropov <81047355+123edi10@users.noreply.github.com> Date: Mon, 28 Oct 2024 08:15:33 +0200 Subject: [PATCH] Fix JNI ERROR --- index.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 198bae6..246e88e 100644 --- a/index.js +++ b/index.js @@ -214,29 +214,20 @@ class Runtime { const { vm, api } = this; const env = vm.getEnv(); - const classHandles = []; const addGlobalReference = api['art::JavaVMExt::AddGlobalRef']; const { vm: vmHandle } = api; withRunnableArtThread(vm, env, thread => { const collectClassHandles = makeArtClassVisitor(klass => { - classHandles.push(addGlobalReference(vmHandle, thread, klass)); + const handle = addGlobalReference(vmHandle, thread, klass); + const className = env.getClassName(handle); + callbacks.onMatch(className, handle); + env.deleteGlobalRef(handle); return true; }); api['art::ClassLinker::VisitClasses'](api.artClassLinker.address, collectClassHandles); }); - try { - classHandles.forEach(handle => { - const className = env.getClassName(handle); - callbacks.onMatch(className, handle); - }); - } finally { - classHandles.forEach(handle => { - env.deleteGlobalRef(handle); - }); - } - callbacks.onComplete(); }