protected synchronized void dispose(boolean cache) {
        if (kidsReferences != null) {
            if (!cache) {
                kidsReferences.clear();
                kidsReferences.trimToSize();
            }
        }
        if (kidsPageAndPages != null) {
            for (Object pageOrPages : kidsPageAndPages) {
                if (pageOrPages instanceof Page)
                    ((Page) pageOrPages).dispose(cache);
                else if (pageOrPages instanceof PageTree)
                    ((PageTree) pageOrPages).dispose(cache);
            }
            if (!cache) {
                kidsPageAndPages.clear();
                kidsPageAndPages.trimToSize();
            }
        }
        /*
         * If resources is non-null, then at least one page has got a reference
         * to it. At which point we'll wait for the last page to reference it
         * do make the call to dispose.
         *
         * It is also possible for type3 fonts to use a resource, so we better
         * go through the motions to remove the resource, as we don't dispose
         * of fonts.
         */
        if (resources != null) {
            boolean disposeSuccess = resources.dispose(cache, this);
            if (disposeSuccess) {
                loadedResources = false;
            }
        }
    }