Code example for ReferenceQueue

Methods: remove

0
                        cl.getConstructor(OutputStream.class);
 
                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");
                System.gc();
 
                Reference<? extends Class<?>> dequeued = queue.remove(TIMEOUT);
                if (dequeued == ref) {
                        System.err.println("\nTEST PASSED");
                } else { 
                        throw new Error();
                }