From ed09bbd4f29dc28dcfb98147143dfcdc3291f52d Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Tue, 20 Aug 2013 04:30:46 +0200 Subject: More recycle stuff (#26) Signed-off-by: Jorge Ruesga --- .../cyanogenmod/wallpapers/photophase/TextureManager.java | 3 +++ .../cyanogenmod/wallpapers/photophase/shapes/OopsShape.java | 9 ++++++++- .../wallpapers/photophase/utils/BitmapUtils.java | 13 +++++++------ .../cyanogenmod/wallpapers/photophase/utils/GLESUtil.java | 2 ++ 4 files changed, 20 insertions(+), 7 deletions(-) (limited to 'src/org/cyanogenmod') diff --git a/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java b/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java index 8f17162..4d4414c 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java +++ b/src/org/cyanogenmod/wallpapers/photophase/TextureManager.java @@ -100,6 +100,7 @@ public class TextureManager implements OnMediaPictureDiscoveredListener { } if (oldTextureInfo.bitmap != null) { oldTextureInfo.bitmap.recycle(); + oldTextureInfo.bitmap = null; } } } else { @@ -287,6 +288,7 @@ public class TextureManager implements OnMediaPictureDiscoveredListener { } // Return the bitmap info.bitmap.recycle(); + info.bitmap = null; } } catch (EmptyQueueException eqex) { // Ignore @@ -294,6 +296,7 @@ public class TextureManager implements OnMediaPictureDiscoveredListener { // Recycle the bitmaps for (GLESTextureInfo ti : sRecycledBitmaps) { ti.bitmap.recycle(); + ti.bitmap = null; } sRecycledBitmaps.clear(); diff --git a/src/org/cyanogenmod/wallpapers/photophase/shapes/OopsShape.java b/src/org/cyanogenmod/wallpapers/photophase/shapes/OopsShape.java index 838acd9..ad69687 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/shapes/OopsShape.java +++ b/src/org/cyanogenmod/wallpapers/photophase/shapes/OopsShape.java @@ -136,10 +136,17 @@ public class OopsShape implements DrawableShape { mMessage = ctx.getString(resourceMessageId); // Load the textures - mOopsImageTexture = GLESUtil.loadTexture(ctx, R.drawable.bg_cid_oops, null, null, true); + mOopsImageTexture = GLESUtil.loadTexture(ctx, R.drawable.bg_cid_oops, null, null, false); Bitmap textBitmap = text2Bitmap(ctx, mMessage); mOopsTextTexture = GLESUtil.loadTexture(textBitmap, null, null); + + // Recycle + mOopsImageTexture.bitmap.recycle(); + mOopsImageTexture.bitmap = null; textBitmap.recycle(); + textBitmap = null; + mOopsTextTexture.bitmap.recycle(); + mOopsTextTexture.bitmap = null; } /** diff --git a/src/org/cyanogenmod/wallpapers/photophase/utils/BitmapUtils.java b/src/org/cyanogenmod/wallpapers/photophase/utils/BitmapUtils.java index 81b0bcf..f7b32b5 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/utils/BitmapUtils.java +++ b/src/org/cyanogenmod/wallpapers/photophase/utils/BitmapUtils.java @@ -77,7 +77,12 @@ public class BitmapUtils { } // Test if the bitmap has exif format, and decode properly - return decodeExifBitmap(file, bitmap); + Bitmap out = decodeExifBitmap(file, bitmap); + if (!out.equals(bitmap)) { + bitmap.recycle(); + bitmap = null; + } + return out; } /** @@ -104,11 +109,7 @@ public class BitmapUtils { matrix.postRotate(270); } // Rotate the bitmap - Bitmap out = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); - if (!out.equals(src)) { - src.recycle(); - } - return out; + return Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true); } catch (IOException e) { // Ignore } diff --git a/src/org/cyanogenmod/wallpapers/photophase/utils/GLESUtil.java b/src/org/cyanogenmod/wallpapers/photophase/utils/GLESUtil.java index ec5834f..a62afe7 100644 --- a/src/org/cyanogenmod/wallpapers/photophase/utils/GLESUtil.java +++ b/src/org/cyanogenmod/wallpapers/photophase/utils/GLESUtil.java @@ -341,6 +341,7 @@ public final class GLESUtil { // Recycle the bitmap if (bitmap != null && recycle) { bitmap.recycle(); + bitmap = null; } } } @@ -390,6 +391,7 @@ public final class GLESUtil { // Recycle the bitmap if (bitmap != null && recycle) { bitmap.recycle(); + bitmap = null; } } } -- cgit v1.2.3