Code example for ReferenceQueue

Methods: remove

                OutputStream os = new ByteArrayOutputStream();
                ObjectOutputStream obj = cons.newInstance(os);
                final ReferenceQueue<Class<?>> queue = new ReferenceQueue<Class<?>>();
                WeakReference<Class<?>> ref = new WeakReference<Class<?>>(cl, queue);
                cl = null;
                obj = null;
                loader = null;
                cons = null;
                systemLoader = null;
                System.err.println("\nStart Garbage Collection right now");
                Reference<? extends Class<?>> dequeued = queue.remove(TIMEOUT);
                if (dequeued == ref) {
                        System.err.println("\nTEST PASSED");
                } else { 
                        throw new Error();
Connect your IDE to all the code out there  Get Codota for Java