summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jeff Sharkey <jsharkey@android.com> 2014-01-16 12:46:37 -0800
committer Mark Renouf <mrenouf@google.com> 2014-03-13 16:07:17 +0000
commit9c5c56eb51e20c0789832d84a520a466a4ab5580 (patch)
treec1b7914fd3283cb869a86648c88a8cff9b376a62
parentcf2b65ce7a5a1d60755a00ae4da6cd6b1101af8c (diff)
Run finalizers before counting for StrictMode.
Otherwise we sometimes end up counting objects strongly referenced by the finalizer queue, and falsely detecting an instance leak. Bug: 12533002 Change-Id: I144c941a3dfb0cbb837b98e80d2f49ffc9ca13c7 (cherry picked from commit 6f3a38f3afd79ed6dddcef5c83cb442d6749e2ff)
-rw-r--r--core/java/android/os/StrictMode.java11
1 files changed, 9 insertions, 2 deletions
diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java
index d794ca674d49..ea71ad8c0563 100644
--- a/core/java/android/os/StrictMode.java
+++ b/core/java/android/os/StrictMode.java
@@ -1449,7 +1449,11 @@ public final class StrictMode {
if (policy.classInstanceLimit.size() == 0) {
return;
}
- Runtime.getRuntime().gc();
+
+ System.gc();
+ System.runFinalization();
+ System.gc();
+
// Note: classInstanceLimit is immutable, so this is lock-free
for (Map.Entry<Class, Integer> entry : policy.classInstanceLimit.entrySet()) {
Class klass = entry.getKey();
@@ -2005,7 +2009,10 @@ public final class StrictMode {
// noticeably less responsive during orientation changes when activities are
// being restarted. Granted, it is only a problem when StrictMode is enabled
// but it is annoying.
- Runtime.getRuntime().gc();
+
+ System.gc();
+ System.runFinalization();
+ System.gc();
long instances = VMDebug.countInstancesOfClass(klass, false);
if (instances > limit) {