ReferenceTable溢出(max = 512)JNI

时间:2012-02-21 04:54:26

标签: android android-ndk java-native-interface

我有点被困在这个...... ReferenceTable溢出(max = 512),我确定它与我在本机方法调用中创建的本地引用数有关...为了解决这个问题,我甚至尝试从本机调用中删除本地引用;但我仍然无法解决问题......我正在传递2D数组;大约是1024 X 1024 ......

以下是我所指的错误跟踪...我确定创建的整数对象数量导致我的情况出现问题......因为您应该能够看到506(I)对象已创建。 ..然后JNI遇到了瓶颈......

/dalvikvm(9498): GC_CONCURRENT freed 1981K, 41% free 6891K/11527K, external 1625K/2137K, paused 2ms+3ms
/dalvikvm(9498): ReferenceTable overflow (max=512)
/dalvikvm(9498): Last 10 entries in JNI local reference table:
/dalvikvm(9498):   502: 0x40710920 cls=[I (4092 bytes)
/dalvikvm(9498):   503: 0x40711920 cls=[I (4092 bytes)
/dalvikvm(9498):   504: 0x40712920 cls=[I (4092 bytes)
/dalvikvm(9498):   505: 0x40713920 cls=[I (4092 bytes)
/dalvikvm(9498):   506: 0x40714920 cls=[I (4092 bytes)
/dalvikvm(9498):   507: 0x40715920 cls=[I (4092 bytes)
/dalvikvm(9498):   508: 0x40716920 cls=[I (4092 bytes)
/dalvikvm(9498):   509: 0x40717920 cls=[I (4092 bytes)
/dalvikvm(9498):   510: 0x40718920 cls=[I (4092 bytes)
/dalvikvm(9498):   511: 0x40719920 cls=[I (4092 bytes)
/dalvikvm(9498): JNI local reference table summary (512 entries):
/dalvikvm(9498):     1 of Ljava/lang/Class; 236B
/dalvikvm(9498):     1 of Ljava/lang/Class; 284B
/dalvikvm(9498):     1 of Ljava/lang/Class; 572B
/dalvikvm(9498):     2 of Ljava/lang/String; 28B (2 unique)
/dalvikvm(9498):   506 of [I 4092B (506 unique)
/dalvikvm(9498):     1 of [Ljava/lang/String; 28B
/dalvikvm(9498): Memory held directly by tracked refs is 2071728 bytes
/dalvikvm(9498): Failed adding to JNI local ref table (has 512 entries)
/dalvikvm(9498): "main" prio=5 tid=1 RUNNABLE
/dalvikvm(9498):   | group="main" sCount=0 dsCount=0 obj=0x4001f198 self=0xce60
/dalvikvm(9498):   | sysTid=9498 nice=0 sched=0/0 cgrp=default handle=-1345006528
/dalvikvm(9498):   | schedstat=( 6990020745 1042358411 1629 )
/dalvikvm(9498):   at pv.ndk.UcMobile.losInitialization(Native Method)
/dalvikvm(9498):   at pv.ndk.NdkActivity.onCreate(NdkActivity.java:69)
/dalvikvm(9498):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
/dalvikvm(9498):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)

以下是我使用的代码: 请让我知道我做错了什么?

JNIEXPORT jboolean JNICALL Java_pv_ndk_UcMobile_losInitialization
  (JNIEnv * env, jobject jobj , jint height, jint width , jobjectArray elements){

   elevData = new unsigned int*[height];

for(i=0; i< height; i++) {
    elevData[i] = new unsigned int[width];

    jintArray oneDim=
    (jintArray)env->GetObjectArrayElement(
                         elements, i);
     jint *element=env->GetIntArrayElements(oneDim, 0);
     for(j=0; j< width; j++) {
         elevData[i][j]= element[j];
     }
     // This does not seem to be providing with the desired result
     // env->DeleteLocalRef(element);

     //I even tried with this approach
     env->ReleaseIntArrayElements(oneDim, element , 0);

  }

return losObject.Init(elevData,1,10,2,2);
}

1 个答案:

答案 0 :(得分:5)

您需要从oneDim对象中删除本地引用:env->DeleteLocalRef(oneDim);