src/main/java/org/jivesoftware/smack/util/Cache.java
protected synchronized void cullCache() {
        // Check if a max cache size is defined.
        if (maxCacheSize < 0) {
            return;
        }

        // See if the cache is too big. If so, clean out cache until it's 10%
        // free.
        if (map.size() > maxCacheSize) {
            // First, delete any old entries to see how much memory that frees.
            deleteExpiredEntries();
            // Next, delete the least recently used elements until 10% of the
            // cache
            // has been freed.
            int desiredSize = (int) (maxCacheSize * .90);
            for (int i = map.size(); i > desiredSize; i--) {
                // Get the key and invoke the remove method on it.
                if (remove(lastAccessedList.getLast().object, true) == null) {
                    log.warn("Error attempting to cullCache with remove("
                            + lastAccessedList.getLast().object.toString()
                            + ") - cacheObject not found in cache!");
                    lastAccessedList.getLast().remove();
                }
            }
        }
    }
protected synchronized void cullCache() {
        // Check if a max cache size is defined.
        if (maxCacheSize < 0) {
            return;
        }

        // See if the cache is too big. If so, clean out cache until it's 10%
        // free.
        if (map.size() > maxCacheSize) {
            // First, delete any old entries to see how much memory that frees.
            deleteExpiredEntries();
            // Next, delete the least recently used elements until 10% of the
            // cache
            // has been freed.
            int desiredSize = (int) (maxCacheSize * .90);
            for (int i = map.size(); i > desiredSize; i--) {
                // Get the key and invoke the remove method on it.
                if (remove(lastAccessedList.getLast().object, true) == null) {
                    log.warn("Error attempting to cullCache with remove("
                            + lastAccessedList.getLast().object.toString()
                            + ") - cacheObject not found in cache!");
                    lastAccessedList.getLast().remove();
                }
            }
        }
    }
Removes the least recently used elements if the cache size is greater
than or equal to the maximum allowed size until the cache is at least 10%
empty.