Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.lang.ref.WeakReference;

public class Main {
    public static void forceGCandWait() {
        Object obj = new Object();
        WeakReference ref = new WeakReference<>(obj);
        obj = null;

        System.gc();
        System.runFinalization();
        /** wait for garbage collector finished*/
        while (ref.get() != null)
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            } //System.gc();
    }
}