protected synchronized void dispose(boolean cache) {
        // Do not null out Library library reference here, without taking
        //   into account that MemoryManager.releaseAllByLibrary(Library)
        //   requires Page to still have Library library in getLibrary()
        // dispose only if the pages has been initiated
        if (isInited) {
            // un-init a page to free up memory
            isInited = false;
            // null data collections for page content
            if (annotations != null) {
                annotations.clear();
                annotations.trimToSize();
            }
            // work through contents and null any stream that have images in them
            if (contents != null) {
                //System.out.println("   Content size " + contents.size());
                for (Stream stream : contents) {
                    stream.dispose(cache);
                }
                contents.clear();
                contents.trimToSize();
            }

            // work through contents and null any stream that have images in them
            if (shapes != null) {
                shapes.dispose();
                shapes = null;
            }

            // work through resources and null any images in the image hash
            if (resources != null) {
                resources.dispose(cache, this);
                resources = null;
            }
            // clean up references in library to avoid slow bleed
            if (cache) {
                // remove the page
                library.removeObject(this.getPObjectReference());
                // annotations
                Object tmp = entries.get(ANNOTS_KEY.getName());
                if (tmp != null && tmp instanceof Vector) {
                    Vector annots = (Vector) tmp;
                    for (Object ref : annots) {
                        if (ref instanceof Reference) {
                            library.removeObject((Reference) ref);
                        }
                    }
                }
            }
        }
        // clear vector of listeners
        if (paintPageListeners != null) {
            paintPageListeners.clear();
            paintPageListeners.trimToSize();
        }
    }