public boolean  dispose(boolean cache, Dictionary referer) {
        synchronized(this) {
            referenceCount--;
            ////System.out.println("Resources.dispose()  " + getPObjectReference() + "  " + uniqueId + "  count: " + referenceCount + "  cache: " + cache);
            ////System.out.println("Resources.dispose()    referer: " + referer.getPObjectReference() + "  " + referer.getClass().getSimpleName());
            // we have a reference so we can't dispose.
            if (referenceCount > 0) {
                ////System.out.println("Resources.dispose()      REDUNDANT");
                return false;
            }
        }

        // NOTE: Make sure not to clear fonts, color spaces, pattern,
        // or extGStat's as this hold reverences to object not the actual
        // object. The only images contain object with a lot of memory

        if (xobjects != null) {
            Enumeration xobjectContent = xobjects.elements();
            while (xobjectContent.hasMoreElements()) {
                Object tmp = xobjectContent.nextElement();
                if (tmp instanceof Stream) {
                    Stream stream = (Stream) tmp;
                    stream.dispose(cache);
                }
                if (tmp instanceof Reference) {
                    Object reference = library.getObject((Reference) tmp);
                    if (reference instanceof Form) {
                        Form form = (Form) reference;
                        form.dispose(cache);
                    }
                    if (reference instanceof Stream) {
                        Stream stream = (Stream) reference;
                        stream.dispose(cache);
                    }
                }
            }
        }
        // remove refernces from library
        clearResource(colorspaces);
        clearResource(fonts);
        clearResource(xobjects);
        clearResource(patterns);
        clearResource(shading);
        clearResource(extGStates);
        return true;
    }