Destroy jni::global_ref while inside a ThreadScope

Summary:
The `BlobCollector` native module stored a `jni::global_ref` as a member,
and its destructor automatically destroys it.
However, as noted in JSI documentation, there is no guarantee that the destructor
is run on a JVM-registered thread. The destructor knew this and used a `jni::ThreadScope`
to do some other JNI behavior, but the global_ref needs to be destroyed during
that ThreadScope as well.

Changelog: [Internal]

Reviewed By: neildhar

Differential Revision: D25372698

fbshipit-source-id: f4eba0b2da154c6eac54d7faeb9ea5bb9260bec9
This commit is contained in:
Riley Dulin
2020-12-07 15:41:08 -08:00
committed by Facebook GitHub Bot
parent 5fb82e7425
commit 72d29ee7d7
@@ -29,6 +29,7 @@ BlobCollector::~BlobCollector() {
static auto removeMethod = jni::findClassStatic(kBlobModuleJavaDescriptor)
->getMethod<void(jstring)>("remove");
removeMethod(blobModule_, jni::make_jstring(blobId_).get());
blobModule_.reset();
});
}