From 6baccd1316dfab9c567cb5a6464e31196912d345 Mon Sep 17 00:00:00 2001 From: icastell Date: Thu, 24 Apr 2014 15:32:43 +0200 Subject: [PATCH] Recycling the original bitmap Recycling the original bitmap which is no longer needed and thus avoid memory leaks. --- BlurEffect/src/com/npi/blureffect/Blur.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/BlurEffect/src/com/npi/blureffect/Blur.java b/BlurEffect/src/com/npi/blureffect/Blur.java index 500bb40..a84393d 100644 --- a/BlurEffect/src/com/npi/blureffect/Blur.java +++ b/BlurEffect/src/com/npi/blureffect/Blur.java @@ -29,6 +29,12 @@ public static Bitmap fastblur(Context context, Bitmap sentBitmap, int radius) { script.setInput(input); script.forEach(output); output.copyTo(bitmap); + + if(bitmap != sentBitmap) { + // To avoid memory leaks + sentBitmap.recycle(); + } + return bitmap; } @@ -258,6 +264,12 @@ public static Bitmap fastblur(Context context, Bitmap sentBitmap, int radius) { Log.e("pix", w + " " + h + " " + pix.length); bitmap.setPixels(pix, 0, w, 0, 0, w, h); + + if(bitmap != sentBitmap) { + // To avoid memory leaks + sentBitmap.recycle(); + } + return (bitmap); }