package org.reference;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;

/**
 * @author shijingui on 2018/1/6
 */
public class WeakRef {

    public static void main(String[] args) {
        MyObject myObject = new MyObject();

        ReferenceQueue weakQueue = new ReferenceQueue<MyObject>();
        WeakReference<MyObject> weakReference = new WeakReference<MyObject>(myObject, weakQueue);
        myObject = null;
        System.gc();
        System.out.println(weakReference.get());

    }

    static class MyObject {
        @Override
        public String toString() {
            return "Weak ref";
        }
    }
}

@@ -635,16 +635,173 @@
        %7D
+%0A%0A        @Override%0A        protected void finalize() throws Throwable %7B%0A            super.finalize();%0A            System.out.println(%22called...%22);%0A        %7D
 %0A    %7D%0A%7D

add ref