Author: dbkr
Date: 2008-05-20 21:53:09 +0000 (Tue, 20 May 2008)
New Revision: 19982
Modified:
trunk/apps/Freemail/src/freemail/utils/PropsFile.java
Log:
Really simplistic reaping of stale (deleted) PropsFiles to address the memory
leak issue.
Modified: trunk/apps/Freemail/src/freemail/utils/PropsFile.java
===================================================================
--- trunk/apps/Freemail/src/freemail/utils/PropsFile.java 2008-05-20
21:46:28 UTC (rev 19981)
+++ trunk/apps/Freemail/src/freemail/utils/PropsFile.java 2008-05-20
21:53:09 UTC (rev 19982)
@@ -36,9 +36,20 @@
public class PropsFile {
// substitute static methods for constructor
- static Hashtable propsList=new Hashtable();
+ private static final Hashtable propsList=new Hashtable();
- public static PropsFile createPropsFile(File f, boolean stopAtBlank) {
+ private static int reapCounter = 0;
+ /// We go through the list and remove stale entries once in this many
times a PropsFile is created
+ private static final int reapEvery = 20;
+
+ public static synchronized PropsFile createPropsFile(File f, boolean
stopAtBlank) {
+ if (reapCounter == reapEvery) {
+ reapOld();
+ reapCounter = 0;
+ } else {
+ ++reapCounter;
+ }
+
String fn=f.getPath();
PropsFile pf=(PropsFile)propsList.get(fn);
@@ -55,6 +66,21 @@
public static PropsFile createPropsFile(File f) {
return createPropsFile(f, false);
}
+
+ public static void reapOld() {
+ Logger.debug(PropsFile.class, "Cleaning up stale PropsFiles");
+
+ Iterator i = propsList.entrySet().iterator();
+
+ while (i.hasNext()) {
+ Map.Entry entry = (Map.Entry)i.next();
+ File f = new File((String)entry.getKey());
+ if (!f.exists()) {
+ Logger.debug(PropsFile.class, "Removing
"+f.getPath());
+ i.remove();
+ }
+ }
+ }
private final File file;
private HashMap data;