How to check memory leak in JNI

In my JNI program, I use

new delete env->NewGlobalRef env->DeleteGlobalRef jvm->AttachCurrentThread jvm->DetachCurrentThread 

What is a good way to check for memory leak strictly?

+4
source share
2 answers

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.

+3
source
  • Try using smart pointers first .
  • As Mankars pointed out, try using the RAII idiom whenever possible to create and delete your global links.
  • Use as few global links as possible.
  • Free local links when building them in a loop

Look here for link management.

Do you already know what your own memory leak code is?

0
source

Source: https://habr.com/ru/post/1394209/


All Articles