Ticket #105 (closed defect: released)
java bindings jni memory leak(s)
| Reported by: | kushkuley | Owned by: | olly |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Xapian-bindings | Version: | 0.9.9 |
| Severity: | normal | Keywords: | |
| Cc: | Blocked By: | ||
| Operating System: | All | Blocking: |
Description
1) java/native/Query.cc
A Relase... is needed for the Get... ( arrow in the code below )
JNIEXPORT jlong JNICALL Java_org_xapian_XapianJNI_query_1newI_3J (JNIEnv *env, jclass clazz, jint op, jlongArray qids) {
TRY
jsize len = env->GetArrayLength?(qids); Query **queries = new Query*[len]; jlong *qid_ptr = env->GetLongArrayElements?(qids, NULL); for (int x=0; x<len; x++) {
queries[x] = _query->get(qid_ptr[x]);
} Query *q = new Query(op_table[op-1], queries, queries+len);
delete[] queries; return _query->put(q);
CATCH(-1)
}
2) java/native/Enquire.cc
This is more complicated. It seems that the code below is necessary for some reason. However, as it is it creates a memory leak -- when enquiry object (e) is deleted in finilize, it's MyQuery? field is not cleaned up. Same is also true for the next jni function in Enquire.cc.
See an additional question ( comment ) in the code below.
JNIEXPORT void JNICALL Java_org_xapian_XapianJNI_enquire_1set_1query (JNIEnv *env, jclass clazz, jlong eid, jlong qid) {
TRY
Enquire *e = _enquire->get(eid); Query *tmp = _query->get(qid);
MyQuery? *q = new MyQuery?(*tmp); q->setMyID(qid); e->set_query(*q);
////// why not this instead of three lines above ?
e->set_query(*tmp);
CATCH(;)
}
Both problems can be reproduced by calling corresponding api calls in a tight loop.
