我有以下问题,从 c++ 我将巨大的字符串 [] 发送到 java。巨大的 = 最多 20 行;我正在做以下事情
jint jtype = 2;
jstring emptyString = env->NewStringUTF("");
jobjectArray data = (jobjectArray)env->NewObjectArray(7, env->FindClass("java/lang/String"), emptyString);
env->SetObjectArrayElement( data,0,env->NewStringUTF(item->get_id().c_str());
env->SetObjectArrayElement( data,1,env->NewStringUTF(item->get_number().c_str());
env->SetObjectArrayElement( data,2,env->NewStringUTF(item->get_fullname().c_str());
env->SetObjectArrayElement( data,3,env->NewStringUTF(item->get_mf().c_str());
env->SetObjectArrayElement( data,4,env->NewStringUTF(item->get_dob().c_str());
env->CallVoidMethod(dao, jsaveItem, data, jtype);
int i;
for (i = 0; i < 5; ++i) {
jstring string = (jstring) env->GetObjectArrayElement(data, i);
env->DeleteLocalRef(string);
}
env->DeleteLocalRef(emptyString);
env->DeleteLocalRef(data);
env->DeleteLocalRef(dao);
这是在一个循环中发生的,所以我正在为要保存在数据库中的每个对象执行此操作,因此您可以想象,它发生了很多次。
所以我很体贴虚拟机并删除了我创建的每个字符串的本地引用,但我仍然得到:
ReferenceTable overflow (max=512)
Last 10 entries in JNI local reference table:
502: 0x40552880 cls=Ljava/lang/String; (28 bytes)
503: 0x405528b8 cls=Ljava/lang/String; (28 bytes)
504: 0x4051f8d0 cls=Ljava/lang/Class; 'Lcom/project/storage/userdata/DataDao;' (212 bytes)
505: 0x4052eb38 cls=Lcom/project/storage/userdata/DataDao; (12 bytes)
506: 0x4051f8d0 cls=Ljava/lang/Class; 'Lcom/project/storage/userdata/DataDao;' (212 bytes)
507: 0x4052eb38 cls=Lcom/project/storage/userdata/DataDao; (12 bytes)
508: 0x4051f8d0 cls=Ljava/lang/Class; 'Lcom/project/storage/userdata/DataDao;' (212 bytes)
509: 0x4052eb38 cls=Lcom/project/storage/userdata/DataDao; (12 bytes)
510: 0x4051f8d0 cls=Ljava/lang/Class; 'Lcom/project/storage/userdata/DataDao;' (212 bytes)
511: 0x4052eb38 cls=Lcom/project/storage/userdata/DataDao; (12 bytes)
JNI local reference table summary (512 entries):
58 of Ljava/lang/Class; 212B (1 unique)
1 of Ljava/lang/Class; 236B
25 of Ljava/lang/Class; 284B (1 unique)
1 of Ljava/lang/Class; 572B
392 of Ljava/lang/String; 28B (392 unique)
1 of Ljava/lang/String; 36B
1 of [Ljava/lang/String; 28B
2 of [Ljava/lang/String; 92B (2 unique)
31 of Lcom/project/storage/userdata/DataDao; 12B (1 unique)
Memory held directly by tracked refs is 12540 bytes
关于为什么会发生溢出的任何想法?我究竟做错了什么?