From af85392b5142c6332da48260c0f3be5e990a19b2 Mon Sep 17 00:00:00 2001 From: Tim Murray Date: Mon, 15 Oct 2018 16:50:23 -0700 Subject: [PATCH 1/2] wm: recycle bitmaps immediately in TaskSnapshotPersister Bitmap created in TaskSnapshotPersister are very short lived and shouldn't be left around in the Java heap. Test: boot, switch apps, works bug 117795621 Exempt-From-Owner-Approval: approved in another branch Change-Id: I4b5e0db50c2b7adaa71cb0d22535c1b37c7523e8 --- .../java/com/android/server/wm/TaskSnapshotPersister.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/services/core/java/com/android/server/wm/TaskSnapshotPersister.java b/services/core/java/com/android/server/wm/TaskSnapshotPersister.java index 21e807eee1e89..6fd179550f008 100644 --- a/services/core/java/com/android/server/wm/TaskSnapshotPersister.java +++ b/services/core/java/com/android/server/wm/TaskSnapshotPersister.java @@ -17,6 +17,7 @@ package com.android.server.wm; import static android.graphics.Bitmap.CompressFormat.*; + import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; @@ -361,6 +362,7 @@ class TaskSnapshotPersister { // For snapshots with reduced resolution, do not create or save full sized bitmaps if (mSnapshot.isReducedResolution()) { + swBitmap.recycle(); return true; } @@ -373,6 +375,8 @@ class TaskSnapshotPersister { Slog.e(TAG, "Unable to open " + file + " for persisting.", e); return false; } + reduced.recycle(); + swBitmap.recycle(); return true; } } From e0b5e846f881035a6f0c49d2a85c79fa2c3d4c26 Mon Sep 17 00:00:00 2001 From: Tim Murray Date: Mon, 15 Oct 2018 16:29:15 -0700 Subject: [PATCH 2/2] hwui: purge malloc pages on bitmap destruction Immediately purge malloc pages on bitmap destruction. Bitmaps are often big and can cause memory to stay high for much longer than it should. Test: boots and works bug 117795621 Change-Id: If2e8c5f1fc07039cf3dc3edcd3dc06861dbce1a1 --- libs/hwui/hwui/Bitmap.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/hwui/hwui/Bitmap.cpp b/libs/hwui/hwui/Bitmap.cpp index b04194f378bc5..753557c2e1208 100644 --- a/libs/hwui/hwui/Bitmap.cpp +++ b/libs/hwui/hwui/Bitmap.cpp @@ -224,6 +224,7 @@ Bitmap::~Bitmap() { break; case PixelStorageType::Heap: free(mPixelStorage.heap.address); + mallopt(M_PURGE, 0); break; case PixelStorageType::Hardware: auto buffer = mPixelStorage.hardware.buffer;