diff --git a/lib/src/main/cpp/libkiwix/book.cpp b/lib/src/main/cpp/libkiwix/book.cpp index 1c8e8b0..84d4508 100644 --- a/lib/src/main/cpp/libkiwix/book.cpp +++ b/lib/src/main/cpp/libkiwix/book.cpp @@ -95,6 +95,7 @@ METHOD0(jobjectArray, getIllustrations) { for (auto illu: illustrations) { auto wrapper = BUILD_WRAPPER("org/kiwix/libkiwix/Illustration", illu); env->SetObjectArrayElement(retArray, index++, wrapper); + env->DeleteLocalRef(wrapper); } return retArray; } CATCH_EXCEPTION(nullptr) diff --git a/lib/src/main/cpp/libkiwix/library.cpp b/lib/src/main/cpp/libkiwix/library.cpp index f65828b..20dc842 100644 --- a/lib/src/main/cpp/libkiwix/library.cpp +++ b/lib/src/main/cpp/libkiwix/library.cpp @@ -104,6 +104,7 @@ METHOD(jobjectArray, getBookmarks, jboolean onlyValidBookmarks) { shared_ptr* handle = new shared_ptr(new kiwix::Bookmark(std::move(bookmark))); jobject wrapper = env->NewObject(wrapperClass, initMethod, reinterpret_cast(handle)); env->SetObjectArrayElement(retArray, index++, wrapper); + env->DeleteLocalRef(wrapper); } return retArray; } CATCH_EXCEPTION(nullptr) diff --git a/lib/src/main/cpp/utils.h b/lib/src/main/cpp/utils.h index e5aee6f..f2c9e60 100644 --- a/lib/src/main/cpp/utils.h +++ b/lib/src/main/cpp/utils.h @@ -263,6 +263,7 @@ template<> struct JTypeArray{ for(size_t index=0; indexSetObjectArrayElement(array, index, jElem); + env->DeleteLocalRef(jElem); } } };