Make sure that each new , env->NewGlobalRef and jvm->AttachCurrentThread is in the constructor of the object, which calls the corresponding maladaptation function in its destructor.
This is a method called RAII , which is vital for writing any valid C ++ program.
source share