Skip to content

Commit a139c21

Browse files
committed
Additional resource cleanup in RSBlur
When the blur is finished, the input, output, and blur are all destroyed, along with the renderscript instance. This resolves a strictmode 'resource acquired but never released' violation.
1 parent c3f09cd commit a139c21

File tree

1 file changed

+15
-4
lines changed
  • transformations/src/main/java/jp/wasabeef/glide/transformations/internal

1 file changed

+15
-4
lines changed

transformations/src/main/java/jp/wasabeef/glide/transformations/internal/RSBlur.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ public class RSBlur {
3131
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
3232
public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSRuntimeException {
3333
RenderScript rs = null;
34+
Allocation input = null;
35+
Allocation output = null;
36+
ScriptIntrinsicBlur blur = null;
3437
try {
3538
rs = RenderScript.create(context);
3639
rs.setMessageHandler(new RenderScript.RSMessageHandler());
37-
Allocation input =
38-
Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
40+
input = Allocation.createFromBitmap(rs, bitmap, Allocation.MipmapControl.MIPMAP_NONE,
3941
Allocation.USAGE_SCRIPT);
40-
Allocation output = Allocation.createTyped(rs, input.getType());
41-
ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
42+
output = Allocation.createTyped(rs, input.getType());
43+
blur = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
4244

4345
blur.setInput(input);
4446
blur.setRadius(radius);
@@ -48,6 +50,15 @@ public static Bitmap blur(Context context, Bitmap bitmap, int radius) throws RSR
4850
if (rs != null) {
4951
rs.destroy();
5052
}
53+
if (input != null) {
54+
input.destroy();
55+
}
56+
if (output != null) {
57+
output.destroy();
58+
}
59+
if (blur != null) {
60+
blur.destroy();
61+
}
5162
}
5263

5364
return bitmap;

0 commit comments

Comments
 (0)