jni 内存泄露 local reference table overflow (max=512)

01-02 00:02:35.064: E/dalvikvm(4223): JNI ERROR (app bug): local reference table overflow (max=512)

 

向JNI传递大量的数据,或new出大量对象时,如果不及时释放,则会造成上述错误。

 

1.在将java string转换为native string之后,要调用ReleaseStringUTFChars释放。

 

if (MNull != pszPath && MNull != strJString)
{
env->ReleaseStringUTFChars(strJString, pszPath);
}

2.用完java传递过来的obj之后,调用(env)->DeleteLocalRef(obj);释放

 

参考资料:

http://stackoverflow.com/questions/4174453/android-native-process-provoke-referencetable-overflow-after-a-while-android-n

 

http://stackoverflow.com/questions/9372373/referencetable-overflow-max-512-jni

posted @ 2012-05-11 09:21  wsjisji  阅读(14551)  评论(0编辑  收藏  举报