summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorChet Haase <chet@google.com>2012-10-22 15:07:26 -0700
committerChet Haase <chet@google.com>2012-10-22 15:25:19 -0700
commit547e66531d521eb1eadac87edb0f79f8c2f1bbe0 (patch)
treeb7687d438e358ace879a20228d0c2c6a820d0c58 /graphics
parentd6e3ad54907ec085aa41e5c77296e9f385c22e67 (diff)
downloadframeworks_base-547e66531d521eb1eadac87edb0f79f8c2f1bbe0.zip
frameworks_base-547e66531d521eb1eadac87edb0f79f8c2f1bbe0.tar.gz
frameworks_base-547e66531d521eb1eadac87edb0f79f8c2f1bbe0.tar.bz2
Don't null the reference to Bitmap pixels until we're really ready
A change in the VM triggers a native memory error more aggressively than before, showing that there's a bug in the logic of recycling bitmaps. Since the pixel memory is allocated on the Java heap, nulling out the reference to that memory in the Java level Bitmap object can cause that memory to get collected at any time. Meanwhile, we may have a reference to that memory at the native level for rendering purposes, causing an error if/when we access that memory after it has been collected by the VM. The fix is to avoid setting the reference to the pixels to null unless we are not referring to it in native code. This is determined at the time we call recycle() - we return a boolean to indicate whether the native code is still using the memory. if not, the Java code can null out the reference and allow the VM to collect it. Otherwise, it will get collected later when the encompassing Bitmap object is collected. Issue #7339156 HTML5 tests crash the app (Vellamo) Change-Id: I3a0d6b9a6c5dd3b86cc2b0ff7719007e774b5e3c
Diffstat (limited to 'graphics')
-rw-r--r--graphics/java/android/graphics/Bitmap.java13
1 files changed, 9 insertions, 4 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index 22ecc61..688fd7a 100644
--- a/graphics/java/android/graphics/Bitmap.java
+++ b/graphics/java/android/graphics/Bitmap.java
@@ -201,9 +201,14 @@ public final class Bitmap implements Parcelable {
*/
public void recycle() {
if (!mRecycled) {
- mBuffer = null;
- nativeRecycle(mNativeBitmap);
- mNinePatchChunk = null;
+ if (nativeRecycle(mNativeBitmap)) {
+ // return value indicates whether native pixel object was actually recycled.
+ // false indicates that it is still in use at the native level and these
+ // objects should not be collected now. They will be collected later when the
+ // Bitmap itself is collected.
+ mBuffer = null;
+ mNinePatchChunk = null;
+ }
mRecycled = true;
}
}
@@ -1391,7 +1396,7 @@ public final class Bitmap implements Parcelable {
private static native Bitmap nativeCopy(int srcBitmap, int nativeConfig,
boolean isMutable);
private static native void nativeDestructor(int nativeBitmap);
- private static native void nativeRecycle(int nativeBitmap);
+ private static native boolean nativeRecycle(int nativeBitmap);
private static native boolean nativeCompress(int nativeBitmap, int format,
int quality, OutputStream stream,