diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2015-10-02 11:39:30 +0200 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2015-10-02 11:39:30 +0200 |
commit | 4b62bd256d9641d8812741a71be8f6db224ef601 (patch) | |
tree | 9fccfe06b352fb892902bc17232975c84ac2c527 | |
parent | 2b9b700c96f7dc0df852a55b115a61d5573bb872 (diff) |
properly recycle bitmaps
-rw-r--r-- | src/main/java/eu/siacs/conversations/persistance/FileBackend.java | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java index f5549f926..474951db1 100644 --- a/src/main/java/eu/siacs/conversations/persistance/FileBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/FileBackend.java @@ -112,7 +112,11 @@ public class FileBackend { scalledW = size; scalledH = (int) (h / ((double) w / size)); } - return Bitmap.createScaledBitmap(originalBitmap, scalledW, scalledH, true); + Bitmap result = Bitmap.createScaledBitmap(originalBitmap, scalledW, scalledH, true); + if (originalBitmap != null && !originalBitmap.isRecycled()) { + originalBitmap.recycle(); + } + return result; } else { return originalBitmap; } @@ -123,7 +127,11 @@ public class FileBackend { int h = bitmap.getHeight(); Matrix mtx = new Matrix(); mtx.postRotate(degree); - return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); + Bitmap result = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); + if (bitmap != null && !bitmap.isRecycled()) { + bitmap.recycle(); + } + return result; } public boolean useImageAsIs(Uri uri) { @@ -227,7 +235,6 @@ public class FileBackend { if (rotation > 0) { scaledBitmap = rotate(scaledBitmap, rotation); } - boolean success = scaledBitmap.compress(Config.IMAGE_FORMAT, Config.IMAGE_QUALITY, os); if (!success) { throw new FileCopyException(R.string.error_compressing_image); @@ -288,7 +295,6 @@ public class FileBackend { throw new FileNotFoundException(); } thumbnail = resize(fullsize, size); - fullsize.recycle(); int rotation = getRotation(file); if (rotation > 0) { thumbnail = rotate(thumbnail, rotation); @@ -447,6 +453,9 @@ public class FileBackend { Bitmap dest = Bitmap.createBitmap(newWidth, newHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(dest); canvas.drawBitmap(source, null, targetRect, null); + if (source != null && !source.isRecycled()) { + source.recycle(); + } return dest; } catch (FileNotFoundException e) { return null; @@ -470,6 +479,9 @@ public class FileBackend { Bitmap output = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); canvas.drawBitmap(input, null, target, null); + if (input != null && !input.isRecycled()) { + input.recycle(); + } return output; } |