From fbff7117abac7a335c6bc2e2f8b927a8dac5753e Mon Sep 17 00:00:00 2001 From: John Reck Date: Tue, 6 Jun 2017 12:14:04 -0700 Subject: [PATCH] Clear native shader when Paint shader changes Since Recents never goes away that means TaskViewThumbnail never goes away which in turn means mDrawPaint never goes away. mDrawPaint has a setShader(null) called on it to release the BitmapShader it was previously drawn with, but that change didn't push down to native until the next time the paint was used. As a result, the Paint held on to a reference to the bitmap. The fix is simple, when the shader is changed simply push down an immediate clear of the native shader. Since the bitmap of a BitmapShader isn't changeable we don't need to worry about clearing references for shader mutation, merely when Paint#setShader() happens. Bug: 38258699 Test: Open & close recents, observe EGL memory immediately returns to sub-5MB. Change-Id: I6742efa8ae8dfca76b62a06bc1a1a00646feba64 --- graphics/java/android/graphics/Paint.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java index e3b47405e0d4e..f931d21380aa7 100644 --- a/graphics/java/android/graphics/Paint.java +++ b/graphics/java/android/graphics/Paint.java @@ -1036,6 +1036,8 @@ public class Paint { // old shader's pointer may be reused by another shader allocation later if (mShader != shader) { mNativeShader = -1; + // Release any native references to the old shader content + nSetShader(mNativePaint, 0); } // Defer setting the shader natively until getNativeInstance() is called mShader = shader;