Created
April 17, 2013 02:21
-
-
Save japgolly/5401310 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onStop() { | |
// Release memory held by background bitmaps | |
AndroidUtils.releaseBackgroundImageMemory(root); | |
AndroidUtils.releaseBackgroundImageMemory(decorFrame); | |
super.onStop(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Releases memory held by a view's background image. | |
* <p> | |
* On Android 4.2 you'll also need to turn off hardware acceleration else the memory won't be released. Instead of | |
* Bitmaps you'll just end up with GLES20DisplayList instances consuming the exact same amount of memory. | |
*/ | |
@SuppressWarnings("deprecation") | |
public static void releaseBackgroundImageMemory(View v) { | |
final Drawable d = v.getBackground(); | |
if (d != null) { | |
d.setCallback(null); | |
if (d instanceof BitmapDrawable) { | |
BitmapDrawable b = (BitmapDrawable) d; | |
Bitmap bitmap = b.getBitmap(); | |
if (bitmap != null) { | |
bitmap.recycle(); | |
} | |
} | |
} | |
v.setBackgroundDrawable(null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment