List of usage examples for com.google.common.testing GcFinalization awaitClear
public static void awaitClear(final WeakReference<?> ref)
From source file:com.google.inject.internal.WeakKeySetUtils.java
public static void awaitClear(WeakReference<?> ref) { // 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. Object data = ref.get();// w ww.j a v a 2 s.c om ReferenceQueue<Object> queue = null; WeakReference extraRef = null; if (data != null) { queue = new ReferenceQueue<Object>(); extraRef = new WeakReference<Object>(data, queue); data = null; } GcFinalization.awaitClear(ref); if (queue != null) { try { assertSame("queue didn't return ref in time", extraRef, queue.remove(5000)); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } } }