BitmapUtils { public static void recycleBitmapFromImageView(ImageView imageView) { if (imageView != null && imageView.getDrawable() != null && imageView.getDrawable() instanceof BitmapDrawable){ final Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap(); recycleBitmap(bitmap); imageView.setImageBitmap(null); } } private  BitmapUtils(); static void recycleBitmapFromImageView(ImageView imageView); static void recycleBitmap(Bitmap bitmap); static byte[] bitmapToBytes(Bitmap bitmap);  }
@Test public void testRecycleBitmapFromImageView(){ ImageView imageView = new ImageView(context); Bitmap testBitmap = createTestBitmap(); imageView.setImageBitmap(testBitmap); BitmapUtils.recycleBitmapFromImageView(imageView); assertTrue(testBitmap.isRecycled()); assertNull(((BitmapDrawable)imageView.getDrawable()).getBitmap()); }