Skip to content
Permalink
Browse files

[JENKINS-15156] Refactored fix.

Originally-Committed-As: fe95fc53f891542e63e24a64c0b7add60ac91c64
  • Loading branch information
johnou committed Feb 6, 2013
1 parent d17b31a commit 6856f5db18f4295043438e4018e95bd454bdd0ca
Showing with 17 additions and 0 deletions.
  1. +17 −0 test/src/main/java/org/jvnet/hudson/test/MemoryAssert.java
@@ -27,6 +27,7 @@
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
@@ -128,4 +129,20 @@ public static void assertHeapUsage(Object o, int max) throws Exception {
return elements;
}

/**
* Forces GC by causing an OOM and then verifies the given {@link WeakReference} has been garbage collected.
* @param reference object used to verify garbage collection.
*/
public static void assertGC(WeakReference<?> reference) {
Set<Object[]> objects = new HashSet<Object[]>();
while (true) {
try {
objects.add(new Object[1024]);
} catch (OutOfMemoryError ignore) {
break;
}
}
assertTrue(reference.get() == null);
}

}

0 comments on commit 6856f5d

Please sign in to comment.
You can’t perform that action at this time.