From 84af10f7e17bc8e934c717b92a3c88a02aab1403 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Mon, 4 Jul 2011 17:42:58 +0100 Subject: 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. --- android/src/com/artifex/mupdf/MuPDFActivity.java | 19 ++++++++++++++++--- android/src/com/artifex/mupdf/MuPDFCore.java | 5 +++++ 2 files changed, 21 insertions(+), 3 deletions(-) (limited to 'android/src') 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(); + } } -- cgit v1.2.3