Skip to content

Commit

Permalink
Assign an unused instance to a variable.
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 437337214
  • Loading branch information
kluever authored and Caliper Team committed Mar 25, 2022
1 parent 6742cf9 commit a0ff759
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions caliper-util/src/main/java/com/google/caliper/util/Util.java
Expand Up @@ -119,12 +119,17 @@ public static void forceGc() {
System.gc();
System.runFinalization();
final CountDownLatch latch = new CountDownLatch(1);
new Object() {
@Override
protected void finalize() {
latch.countDown();
}
};

// Create, then throw away, an object that will trigger the latch when finalized away.
Object unused =
new Object() {
@Override
protected void finalize() {
latch.countDown();
}
};
unused = null;

System.gc();
System.runFinalization();
try {
Expand Down

0 comments on commit a0ff759

Please sign in to comment.