Example usage for com.google.common.testing GcFinalization awaitFullGc

List of usage examples for com.google.common.testing GcFinalization awaitFullGc

Introduction

In this page you can find the example usage for com.google.common.testing GcFinalization awaitFullGc.

Prototype

public static void awaitFullGc() 

Source Link

Document

Tries to perform a "full" garbage collection cycle (including processing of weak references and invocation of finalize methods) and waits for it to complete.

Usage

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);
    }
}