From 69a9c170b39cf26293a5b6d80e9aeed47b17b385 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Tue, 6 Jun 2017 14:01:29 -0700 Subject: [PATCH] Run explicit GC to clear references to bitmaps earlier. Bug: 38258699 Test: Open Recents, dump meminfo, close Recents, wait, dump meminfo Change-Id: Ibdcf94aee4fac9abcde64e30ae1f13cbb551fec0 --- .../android/systemui/recents/RecentsActivity.java | 3 +++ .../systemui/recents/misc/SystemServicesProxy.java | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java index 76970610bc759..ba3bcc79da442 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java @@ -514,6 +514,9 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD RecentsActivityLaunchState launchState = config.getLaunchState(); launchState.reset(); } + + // Force a gc to attempt to clean up bitmap references more quickly (b/38258699) + Recents.getSystemServices().gc(); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java index cbfa0e58add12..1f13830ec1cc6 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java +++ b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java @@ -361,6 +361,19 @@ public class SystemServicesProxy { return sSystemServicesProxy; } + /** + * Requests a gc() from the background thread. + */ + public void gc() { + BackgroundThread.getHandler().post(new Runnable() { + @Override + public void run() { + System.gc(); + System.runFinalization(); + } + }); + } + /** * @return whether the provided {@param className} is blacklisted */