Skip to content

Commit

Permalink
[JENKINS-15156] Refactored fix.
Browse files Browse the repository at this point in the history
Originally-Committed-As: fe95fc53f891542e63e24a64c0b7add60ac91c64
  • Loading branch information
johnou committed Feb 6, 2013
1 parent d17b31a commit 6856f5d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/src/main/java/org/jvnet/hudson/test/MemoryAssert.java
Expand Up @@ -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;
Expand Down Expand Up @@ -128,4 +129,20 @@ public static List<HistogramElement> increasedMemory(Callable<Void> callable, Fi
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.