private void checkEnableCacheCleaning() {
        if (cacheSum < maxmemtiles) {
            return;
        }

        for (final OsmFile[] fileRow : fileRows) {
            if (fileRow == null) {
                continue;
            }
            for (OsmFile osmf : fileRow) {
                if (garbageCollectionEnabled && !ghostCleaningDone) {
                    cacheSum -= osmf.cleanGhosts();
                } else {
                    cacheSum -= osmf.collectAll();
                }
            }
        }

        if (garbageCollectionEnabled) {
            ghostCleaningDone = true;
            maxmemtiles *= 2;
        } else {
            cacheSumClean = cacheSum;
            garbageCollectionEnabled = true;
        }
    }
Efficient cache or osmnodes

@author ab
main/src/main/java/cgeo/geocaching/brouter/mapaccess/NodesCache.java