From a74f0dfb7a1e3e87022c94c6d44fc579505ad6e6 Mon Sep 17 00:00:00 2001 From: Ewan Date: Fri, 8 Apr 2022 21:57:30 +0100 Subject: [PATCH 1/2] Android / Blur: Prevent leak by explicitly calling 'Destroy' on allocated renderscript objects. --- .../BlurredTransformation.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/FFImageLoading.Transformations.Droid/BlurredTransformation.cs b/source/FFImageLoading.Transformations.Droid/BlurredTransformation.cs index 837a34a49..d331972b3 100644 --- a/source/FFImageLoading.Transformations.Droid/BlurredTransformation.cs +++ b/source/FFImageLoading.Transformations.Droid/BlurredTransformation.cs @@ -64,6 +64,10 @@ public static Bitmap ToBlurred(Bitmap source, Context context, float radius) script.ForEach(outAlloc); outAlloc.CopyTo(output); + // NOTE: Xamarin.Android Dispose() doesn't call 'destroy' on the allocations or scripts. Therefore, we must manually call it. + outAlloc.Destroy(); + inAlloc.Destroy(); + script.Destroy(); rs.Destroy(); return output; } From 033a9c7670270f066b55c06fc5eacc1446a2d2fa Mon Sep 17 00:00:00 2001 From: Ewan Date: Fri, 8 Apr 2022 21:57:58 +0100 Subject: [PATCH 2/2] Android / Blur: Remove old commented out code. --- .../BlurredTransformation.cs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/source/FFImageLoading.Transformations.Droid/BlurredTransformation.cs b/source/FFImageLoading.Transformations.Droid/BlurredTransformation.cs index d331972b3..d90476369 100644 --- a/source/FFImageLoading.Transformations.Droid/BlurredTransformation.cs +++ b/source/FFImageLoading.Transformations.Droid/BlurredTransformation.cs @@ -71,19 +71,6 @@ public static Bitmap ToBlurred(Bitmap source, Context context, float radius) rs.Destroy(); return output; } - - //Bitmap output = Bitmap.createBitmap(smallBitmap.getWidth(), smallBitmap.getHeight(), smallBitmap.getConfig()); - - //RenderScript rs = RenderScript.create(getContext()); - //ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); - //Allocation inAlloc = Allocation.createFromBitmap(rs, smallBitmap, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_GRAPHICS_TEXTURE); - //Allocation outAlloc = Allocation.createFromBitmap(rs, output); - //script.setRadius(BLUR_RADIUS); - //script.setInput(inAlloc); - //script.forEach(outAlloc); - //outAlloc.copyTo(output); - - //rs.destroy(); } return ToLegacyBlurred(source, context, (int)radius);