Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9c5c56eb authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Mark Renouf
Browse files

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 6f3a38f3)
parent cf2b65ce
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -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) {