diff options
author | Robin Watts <Robin.Watts@artifex.com> | 2011-07-04 17:42:58 +0100 |
---|---|---|
committer | Robin Watts <Robin.Watts@artifex.com> | 2011-07-04 17:42:58 +0100 |
commit | 84af10f7e17bc8e934c717b92a3c88a02aab1403 (patch) | |
tree | 00b9fa6112ef09ce19d80d6ccc5f9b2dd393ef0e /android/jni/mupdf.c | |
parent | 5b5b1842a8c775ddc86ddb354cfe07c6166d4091 (diff) | |
download | mupdf-84af10f7e17bc8e934c717b92a3c88a02aab1403.tar.xz |
Android build lifecycle tweaks; fix leaking.
If the app was hidden, and then restarted, it would leak lots of
memory due to onCreate not only being called on create. To fix
this, we armour the app a bit aginst such problems, including
adding code to destroy the core when the app really is destroyed.
Diffstat (limited to 'android/jni/mupdf.c')
-rw-r--r-- | android/jni/mupdf.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/android/jni/mupdf.c b/android/jni/mupdf.c index 46858e1e..f664bc4b 100644 --- a/android/jni/mupdf.c +++ b/android/jni/mupdf.c @@ -36,6 +36,7 @@ Java_com_artifex_mupdf_MuPDFCore_openFile(JNIEnv * env, jobject thiz, jstring jf char *password = ""; int accelerate = 1; fz_error error; + int pages; filename = (*env)->GetStringUTFChars(env, jfilename, NULL); if (filename == NULL) @@ -64,9 +65,10 @@ Java_com_artifex_mupdf_MuPDFCore_openFile(JNIEnv * env, jobject thiz, jstring jf LOGE("Cannot load page tree: '%s'\n", filename); return 0; } - LOGE("Done! %d pages", pdf_count_pages(xref)); + pages = pdf_count_pages(xref); + LOGE("Done! %d pages", pages); - return pdf_count_pages(xref); + return pages; } JNIEXPORT void JNICALL @@ -196,3 +198,14 @@ Java_com_artifex_mupdf_MuPDFCore_drawPage(JNIEnv *env, jobject thiz, jobject bit return 1; } + +JNIEXPORT void JNICALL +Java_com_artifex_mupdf_MuPDFCore_destroying(JNIEnv * env, jobject thiz) +{ + fz_free_display_list(currentPageList); + currentPageList = NULL; + pdf_free_xref(xref); + xref = NULL; + fz_free_glyph_cache(glyphcache); + glyphcache = NULL; +} |