public void testMemoryLeak() throws Exception {
        if (BeanUtilsTestCase.isPre14JVM()) {
            System.out.println("WARNING: CANNOT TEST MEMORY LEAK ON PRE1.4 JVM");
            return;
        }
        
        // many thanks to Juozas Baliuka for suggesting this methodology
        TestClassLoader loader = new TestClassLoader();
        WeakReference loaderReference = new  WeakReference(loader);
        LocaleBeanUtilsBean.getLocaleBeanUtilsInstance();

        class GetBeanUtilsBeanThread extends Thread {
            
            LocaleBeanUtilsBean beanUtils;
            LocaleConvertUtilsBean convertUtils;
        
            GetBeanUtilsBeanThread() {}
            
            public void run() {
                beanUtils = LocaleBeanUtilsBean.getLocaleBeanUtilsInstance();
                convertUtils = LocaleConvertUtilsBean.getInstance();
                // XXX Log keeps a reference around!
                LogFactory.releaseAll();
            }
            
            public String toString() {
                return "GetBeanUtilsBeanThread";
            }
        }
        
    
        GetBeanUtilsBeanThread thread = new GetBeanUtilsBeanThread();
        WeakReference threadWeakReference = new WeakReference(thread);
        thread.setContextClassLoader(loader);

        thread.start();
        thread.join();
        
        WeakReference beanUtilsReference = new WeakReference(thread.beanUtils);
        WeakReference convertUtilsReference = new WeakReference(thread.convertUtils);
        
        assertNotNull("Weak reference released early (1)", loaderReference.get());
        assertNotNull("Weak reference released early (2)", beanUtilsReference.get());
        assertNotNull("Weak reference released early (4)", convertUtilsReference.get());
        
        // dereference strong references
        loader = null;
        thread.setContextClassLoader(null);
        thread = null;
        
        int iterations = 0;
        int bytz = 2;
        while(true) {
            LocaleBeanUtilsBean.getLocaleBeanUtilsInstance();
            System.gc();
            if(iterations++ > MAX_GC_ITERATIONS){
                fail("Max iterations reached before resource released.");
            }

            if( 
                loaderReference.get() == null &&
                beanUtilsReference.get() == null && 
                convertUtilsReference.get() == null) {
                break;
                
            } else {
                // create garbage:
                byte[] b =  new byte[bytz];
                bytz = bytz * 2;
            }
        }
    }