List of usage examples for com.google.common.testing GcFinalization awaitFullGc
public static void awaitFullGc()
From source file:com.google.inject.internal.WeakKeySetUtils.java
public static void awaitFullGc() { // GcFinalization *should* do it, but doesn't work well in practice... // so we put a second latch and wait for a ReferenceQueue to tell us. ReferenceQueue<Object> queue = new ReferenceQueue<Object>(); WeakReference ref = new WeakReference<Object>(new Object(), queue); GcFinalization.awaitFullGc(); try {//from w w w.ja va 2 s . c o m assertSame("queue didn't return ref in time", ref, queue.remove(5000)); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } }