Fix accumulation of weak reference keys (mem leak) in snapshot cache

This commit is contained in:
Mike Primm 2011-12-28 14:33:32 +08:00 committed by mikeprimm
parent bd92cc37bf
commit babc8cd073
2 changed files with 19 additions and 2 deletions

View File

@ -1076,6 +1076,10 @@ public class MapManager {
if(saverestorepending)
savePending();
if(sscache != null) {
sscache.cleanup();
sscache = null;
}
}
private HashMap<World, File> worldTileDirectories = new HashMap<World, File>();

View File

@ -122,8 +122,10 @@ public class SnapshotCache {
private void processRefQueue() {
Reference<? extends ChunkSnapshot> ref;
while((ref = refqueue.poll()) != null) {
String k = snapcache.reverselookup.get(ref);
if(k != null) snapcache.remove(k);
String k = snapcache.reverselookup.remove(ref);
if(k != null) {
snapcache.remove(k);
}
}
}
/**
@ -141,5 +143,16 @@ public class SnapshotCache {
public void resetStats() {
cache_attempts = cache_success = 0;
}
/**
* Cleanup
*/
public void cleanup() {
if(snapcache != null) {
snapcache.clear();
snapcache.reverselookup.clear();
snapcache.reverselookup = null;
snapcache = null;
}
}
}