NewString((j...">

JNI Explanation DeleteLocalRef

Question 1:

jstring jstrKey;
for(int i=1;i<=1000;++i) {
    LPWSTR strKey = L"string";
    jstrKey = env->NewString((jchar *)strKey, wcslen(strKey));
}
env->DeleteLocalRef(jstrKey);

Question 2:

for(int i=1;i<=1000++i) {
    LPWSTR strKey = L"string";
    jstring jstrKey = env->NewString((jchar *)strKey, wcslen(strKey));
    env->DeleteLocalRef(jstrKey);
}

Am I using DeleteLocalRef correctly in both questions?

Especially in question 1, I remove the local ref after the loop. I think this is correct, and you do not need to call deleteelocalref inside the loop, since I am not creating any new local links.

So there are no problems with use DeleteLocalRef?

+4
source share
2 answers

In both cases, you must call DeleteLocalRef()inside the loop, because each NewString()resolves a new local ref.

JNI , Java. . ref , , .

+6

, , , . .

+1

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


All Articles