Corrected memory leak issue #4.

This commit is contained in:
didfet
2015-03-24 20:47:14 +01:00
parent 055e7ae499
commit 12c17e63b2
3 changed files with 11 additions and 7 deletions

View File

@@ -157,6 +157,13 @@ public class FileState {
public void setOldFileState(FileState oldFileState) {
this.oldFileState = oldFileState;
}
public void deleteOldFileState() {
try {
oldFileState.getRandomAccessFile().close();
oldFileState = null;
} catch(Exception e) {}
}
public Event getFields() {
return fields;

View File

@@ -170,20 +170,17 @@ public class FileWatcher {
}
logger.trace("Refreshing file state");
for(File file : newWatchMap.keySet()) {
for(FileState state : newWatchMap.values()) {
if(logger.isTraceEnabled()) {
logger.trace("Refreshing file : " + file.getCanonicalPath());
logger.trace("Refreshing file : " + state.getFile());
}
FileState state = newWatchMap.get(file);
FileState oldState = state.getOldFileState();
if(oldState == null) {
logger.trace("File has been truncated or created, not retrieving pointer");
} else {
logger.trace("File has not been truncated or created, retrieving pointer");
state.setPointer(oldState.getPointer());
try {
oldState.getRandomAccessFile().close();
} catch(Exception e) {}
state.deleteOldFileState();
}
}