--- android/TrainInfo/src/dk/thoerup/traininfo/util/AndroidTimeoutCache.java 2010/09/08 08:45:18 1031 +++ android/TrainInfo/src/dk/thoerup/traininfo/util/AndroidTimeoutCache.java 2010/09/08 09:29:42 1032 @@ -1,6 +1,10 @@ package dk.thoerup.traininfo.util; import java.util.HashMap; +import java.util.Iterator; +import java.util.Set; + +import android.util.Log; public class AndroidTimeoutCache { @@ -26,13 +30,20 @@ public void purgeOldEntries() { long now = android.os.SystemClock.elapsedRealtime(); + //Log.e("Purge","Purge"); + + Set keyset = cache.keySet(); - for (K key : cache.keySet()) { + for ( Iterator it = keyset.iterator(); it.hasNext() ;) { + K key = it.next(); + CacheItem item = cache.get(key); if ( (item.lastupdate+timeout) < now) { //item too old - cache.remove(key); - } - } + it.remove(); + //Log.e("Purge", "removing"); + } + } + } public void put(K k, V v) {