Reputation: 20460
JNIEXPORT jstring JNICALL Java_com_xxx_xpdf_PdfToText_getTextOnly(JNIEnv *env, jclass obj,
jstring pdf_path) {
const char *pdf = env->GetStringUTFChars(pdf_path, 0);
std::string content;
unsigned int i = getTextFromPDF(pdf, &content);
env->ReleaseStringUTFChars(pdf_path, pdf);
const char *result = content.c_str();
jstring str = env->NewStringUTF(result);
return str;
}
Do I need to relase str
and content
here ? And why ?
Upvotes: 1
Views: 539
Reputation: 310980
No. str
refers to a Java object which continues to exist beyond this JNI method, as it is the return value. content
is a C++ local object which is auto-destroyed when its declaring scope exits.
Upvotes: 2