The Android program always crashes and feels like a memory leak, but the check code finds that the release is released. Ultimately helpless, remove the call in the interface function, use only the following test code.
1 jniexport Jboolean jnicall java_com_example_x_xx_xxx2(JNIENV *env, Jclass, Jbytearray Temp1, Jdoublearray temp2)3 {4jboolean* PARRAYTEMP1 = (jboolean*) env->getprimitivearraycritical (Temp1,0);5jdouble* PARRAYTEMP2 = (jdouble*) env->getprimitivearraycritical (TEMP2,0);6 7 BOOLresult=true;8 9Env->releaseprimitivearraycritical (Temp1, PARRAYTEMP1, jni_commit);TenEnv->releaseprimitivearraycritical (Temp2, parraytemp2,jni_commit); One A returnresult; -}
There is no code in the program, but the call 2000 times, the program will always crash. Later, use the following command
ADB shell SetProp Debug.checkjni 1
See the program always crashes after 512 times. Find the following tips
JNI pinned array reference table dump
Online is the reason for Android reference table , I did not release the buffer, so every time I always add to the reference table, until the maximum value of 1024 (each save Temp1 and temp2 two parameters, Thus 512 times has reached the maximum value of reference table 1024), the program crashes.
Searched for half a day, also did not find a good solution. At last, I looked at the definition of Jni_commit,
It says that Jni_commit is/* Copy content, do not free buffer */. It was then changed to 0, and the code above ran 50,000 times and did not crash.
So said before the release of the program, the last parameter is Jni_commit, the estimated use of more will have problems, fortunately written Android not much, and so on when the time to change it ...
PS, in fact, some of the online reference code in the Getprimitivearraycritical function of the last parameter is used, and releaseprimitivearraycritical may be corresponding to it. Too lazy to test. Let's do it first.
Problems with Android reference table