public static int sizeOfMap(Map<?,?> map)
        throws CannotCalculateSizeException {
        if (map == null) {
            return 0;
        }
        // Base map object -- should be something around this size.
        int size = 36;
        Set<? extends Map.Entry> set = map.entrySet();
        
        // Add in size of each value
        for (Map.Entry<Object, Object> entry : set) {
            size += sizeOfAnything(entry.getKey());
            size += sizeOfAnything(entry.getValue());
        }
        return size;
    }
Returns the size in bytes of a Map object. 

@param map the Map object to determine the size of.
@return the size of the Map object.
@throws CannotCalculateSizeException if the size cannot be calculated
xmppserver/src/main/java/org/jivesoftware/util/cache/CacheSizes.java