transient sclass ImagePreviewCache { // max bytes in memory settable long maxSize; // estimated bytes in memory gettable long totalSize; new TheMap map; class TheMap extends LinkedHashMap { protected bool removeEldestEntry(Map.Entry eldest) { if (totalSize > maxSize) { totalSize -= guessImageSize(eldest.getValue()); true; } false; } } int guessImageSize(BufferedImage image) { ret guessImageSizeInMemory(image); } BufferedImage makeThumbnail(File file) { ret loadImage2(); } }