On Sep 14, 7:37 am, John <
jo-d...@hotmail.com> wrote:
> I've isolated the code down to the following for loop.
>
> for (int i=0; i<1000; i++) {
> jstring str1 = env->NewStringUTF("Unique Id");
> }
>
> When i=505, my Java application inexplicably terminates. Apparently
> JNI cannot handle so many NewStringUTF calls.
Use "adb logcat" to see the failure message from the VM, which will
tell you that you've overflowed your JNI local refs table.
Add "env->DeleteLocalRef(str1)" at an appropriate point in the loop to
avoid the issue.
Read the "JNI Tips" document to understand more about local/global
references.
http://android.git.kernel.org/?p=platform/dalvik.git;a=blob_plain;f=docs/jni-tips.html;hb=HEAD
See in particular the "not excessively allocate" paragraph. (The doc
also has links to the canonical JNI documentation, which you should
definitely read.)