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/src | |
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/src')
-rw-r--r-- | android/src/com/artifex/mupdf/MuPDFActivity.java | 19 | ||||
-rw-r--r-- | android/src/com/artifex/mupdf/MuPDFCore.java | 5 |
2 files changed, 21 insertions, 3 deletions
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(); + } } |