问题描述
我复制从Java多维数组,但我有一些问题,使用后释放内存。
I copied a multidimensional array from java, but i am having some problems to free the memory after using it.
我所做的是:
jfieldID h_valID = (*env)->GetFieldID(env, h_cls, "val", "[[I");
jobjectArray h_val_obj = (*env)->GetObjectField(env, h, h_valID);
int h_val_local[xdim][ydim];
for(i=0; i<xdim; i++)
{
h_val_one_dim = (jintArray) (*env)->GetObjectArrayElement(env, h_val_obj, i);
h_val_elem = (*env)->GetIntArrayElements(env, h_val_one_dim, 0);
for(j=0; j<ydim; j++)
{
h_val_local[i][j] = h_val_elem[j];
}
(*env)->ReleaseIntArrayElements(env, h_val_one_dim, h_val_elem, 0);
(*env)->DeleteLocalRef(env, h_val_one_dim);
}
(*env)->DeleteLocalRef(env, h_val_obj);
我有4个阵列上的方法,所有的参数,我得到的指针,然后使用后释放。
I have 4 more arrays on that method, all on the parameters, i'm getting the pointer then releasing after using it.
int *x = (*env)->GetIntArrayElements(env,x_p,0);
int *y = (*env)->GetIntArrayElements(env,y_p,0);
int *v = (*env)->GetIntArrayElements(env,v_p,0);
int *w = (*env)->GetIntArrayElements(env,w_p,0);
...
(*env)->ReleaseIntArrayElements(env, x_p, x, 0);
(*env)->ReleaseIntArrayElements(env, y_p, y, 0);
(*env)->ReleaseIntArrayElements(env, v_p, v, 0);
(*env)->ReleaseIntArrayElements(env, w_p, w, 0);
对于更大的文件,我得到的参考表溢出。什么我忘了免费或如何解决这个怎么样?
For bigger files, i'm getting overflow on the reference table. What i'm forgetting to free or how do i fix this?
日志:
10-02 14:18:58.885:W / dalvikvm(23598):ReferenceTable溢出(最大值= 1024)
10-02 14:18:58.885:W / dalvikvm(23598):在JNI固定数组引用表中最后10个条目:
10-02 14:18:58.885: W/dalvikvm(23598): Last 10 entries in JNI pinned array reference table:
10-02 14:18:58.885:W / dalvikvm(23598):1014:0x46109fe8 CLS = I(24字节)
10-02 14:18:58.885: W/dalvikvm(23598): 1014: 0x46109fe8 cls=[I (24 bytes)
10-02 14:18:58.885:W / dalvikvm(23598):1015:0x4610a008 CLS = I(24字节)
10-02 14:18:58.885: W/dalvikvm(23598): 1015: 0x4610a008 cls=[I (24 bytes)
10-02 14:18:58.885:W / dalvikvm(23598):1016:0x46109fa8 CLS = I(24字节)
10-02 14:18:58.885: W/dalvikvm(23598): 1016: 0x46109fa8 cls=[I (24 bytes)
10-02 14:18:58.885:W / dalvikvm(23598):1017:0x46109fc8 CLS = I(24字节)
10-02 14:18:58.885: W/dalvikvm(23598): 1017: 0x46109fc8 cls=[I (24 bytes)
10-02 14:18:58.885:W / dalvikvm(23598):1018:0x46109fe8 CLS = I(24字节)
10-02 14:18:58.885: W/dalvikvm(23598): 1018: 0x46109fe8 cls=[I (24 bytes)
10-02 14:18:58.885:W / dalvikvm(23598):1019:0x4610a008 CLS = I(24字节)
10-02 14:18:58.885: W/dalvikvm(23598): 1019: 0x4610a008 cls=[I (24 bytes)
10-02 14:18:58.885:W / dalvikvm(23598):1020:0x46109fa8 CLS = I(24字节)
10-02 14:18:58.885: W/dalvikvm(23598): 1020: 0x46109fa8 cls=[I (24 bytes)
10-02 14:18:58.885:W / dalvikvm(23598):1021:0x46109fc8 CLS = I(24字节)
10-02 14:18:58.885: W/dalvikvm(23598): 1021: 0x46109fc8 cls=[I (24 bytes)
10-02 14:18:58.885:W / dalvikvm(23598):1022:0x46109fe8 CLS = I(24字节)
10-02 14:18:58.885: W/dalvikvm(23598): 1022: 0x46109fe8 cls=[I (24 bytes)
10-02 14:18:58.885:W / dalvikvm(23598):1023:0x4610a008 CLS = I(24字节)
10-02 14:18:58.885: W/dalvikvm(23598): 1023: 0x4610a008 cls=[I (24 bytes)
10-02 14:18:58.885:W / dalvikvm(23598):JNI固定阵列参考表摘要(1024项):
10-02 14:18:58.885: W/dalvikvm(23598): JNI pinned array reference table summary (1024 entries):
10-02 14:18:58.885:W / dalvikvm(23598):1024 [我24B(4唯一的)
10-02 14:18:58.885: W/dalvikvm(23598): 1024 of [I 24B (4 unique)
10-02 14:18:58.885:W / dalvikvm(23598):直接追踪裁判举办内存是96字节
10-02 14:18:58.885: W/dalvikvm(23598): Memory held directly by tracked refs is 96 bytes
10-02 14:18:58.885:E / dalvikvm(23598):无法加入到JNI固定数组引用表(1024项)
10-02 14:18:58.885: E/dalvikvm(23598): Failed adding to JNI pinned array ref table (1024 entries)
THX
推荐答案
我发现我在做什么错的,更好的,我忘了做。我在code另一个返回点,但我忘了返回在这种情况下,之前发布的阵列,我只是释放它的函数结束。
I found out what i was doing wrong, better, what i forgot to do. I have another return point in the code, but i forgot to release the arrays before returning in that case, i was only releasing it at the end of the function.
这篇关于失败增加了JNI固定数组引用表(1024项)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!