summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorRobin Watts <Robin.Watts@artifex.com>2011-07-04 17:42:58 +0100
committerRobin Watts <Robin.Watts@artifex.com>2011-07-04 17:42:58 +0100
commit84af10f7e17bc8e934c717b92a3c88a02aab1403 (patch)
tree00b9fa6112ef09ce19d80d6ccc5f9b2dd393ef0e /android
parent5b5b1842a8c775ddc86ddb354cfe07c6166d4091 (diff)
downloadmupdf-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')
-rw-r--r--android/ReadMe.txt6
-rw-r--r--android/jni/mupdf.c17
-rw-r--r--android/src/com/artifex/mupdf/MuPDFActivity.java19
-rw-r--r--android/src/com/artifex/mupdf/MuPDFCore.java5
4 files changed, 39 insertions, 8 deletions
diff --git a/android/ReadMe.txt b/android/ReadMe.txt
index 61a6446a..c46c88b6 100644
--- a/android/ReadMe.txt
+++ b/android/ReadMe.txt
@@ -96,12 +96,12 @@ done once). With the emulator running type:
(where obviously ../../MyTests/pdf_reference17.pdf is altered for your
machine). (adb lives in <sdk>/platform-tools if it's not on your path).
-13) With the emulator running (see step 9), execute
+13) With the emulator running (see step 11), execute
ant install
-and that will copy MuPDF into the emulator where you can run it from the
-launchpad screen.
+('ant.bat install' on Windows) and that will copy MuPDF into the emulator
+where you can run it from the launchpad screen.
14) To see debug messages from the emulator (including stdout/stderr from
our app), execute:
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;
+}
diff --git a/android/src/com/artifex/mupdf/MuPDFActivity.java b/android/src/com/artifex/mupdf/MuPDFActivity.java
index 0561f01b..d5ba3bd8 100644
--- a/android/src/com/artifex/mupdf/MuPDFActivity.java
+++ b/android/src/com/artifex/mupdf/MuPDFActivity.java
@@ -56,9 +56,12 @@ public class MuPDFActivity extends Activity
{
PixmapView pixmapView;
- core = (MuPDFCore)getLastNonConfigurationInstance();
- if (core == null)
+ if (core == null) {
+ core = (MuPDFCore)getLastNonConfigurationInstance();
+ }
+ if (core == null) {
core = openFile();
+ }
if (core == null)
{
/* FIXME: Error handling here! */
@@ -118,7 +121,17 @@ public class MuPDFActivity extends Activity
public Object onRetainNonConfigurationInstance()
{
- return core;
+ MuPDFCore mycore = core;
+ core = null;
+ return mycore;
+ }
+
+ public void onDestroy()
+ {
+ if (core != null)
+ core.onDestroy();
+ core = null;
+ super.onDestroy();
}
private class MyButtonHandler implements OnClickListener
diff --git a/android/src/com/artifex/mupdf/MuPDFCore.java b/android/src/com/artifex/mupdf/MuPDFCore.java
index d867b1b1..321b4a64 100644
--- a/android/src/com/artifex/mupdf/MuPDFCore.java
+++ b/android/src/com/artifex/mupdf/MuPDFCore.java
@@ -23,6 +23,7 @@ public class MuPDFCore
int pageW, int pageH,
int patchX, int patchY,
int patchW, int patchH);
+ public static native void destroying();
public MuPDFCore(String filename) throws Exception
{
@@ -46,4 +47,8 @@ public class MuPDFCore
this.pageWidth = getPageWidth();
this.pageHeight = getPageHeight();
}
+
+ public void onDestroy() {
+ destroying();
+ }
}