The DefaultRefDeleter of these classes sometimes gets called on another thread than the one they were created on. This is because a class that composes them is held with a shared pointer that is shared between threads (e.g. std::shared_ptr`) and sometimes another thread holds to it longer. This causes problems because the env pointer of the creation thread is used, which cannot be used on another thread.
From the source code of jni.hpp:
The default policy is to delete the reference using the same JNIEnv as was passed to the constructor, but in cases where the object may be deleted on a different thread (commonly, the Java finalizer thread), EnvGettingDeleter or EnvAttachingDeleter may be needed.
There are likely other cases where we need to make this change. But these are the places where a crash is either reported or observed.
The`) and sometimes another thread holds to it longer. This causes problems because the env pointer of the creation thread is used, which cannot be used on another thread.
DefaultRefDeleter
of these classes sometimes gets called on another thread than the one they were created on. This is because a class that composes them is held with a shared pointer that is shared between threads (e.g. std::shared_ptrFrom the source code of jni.hpp:
There are likely other cases where we need to make this change. But these are the places where a crash is either reported or observed.
Closes #2045