public void Update() { List <string> delList = new List <string>(); foreach (KeyValuePair <string, List <ResourceCacheItem> > kv in cacheDict) { for (int i = kv.Value.Count; i >= 0; i--) { ResourceCacheItem item = kv.Value[i]; item.retainTime--; if (item.retainTime <= 0) { kv.Value.RemoveAt(i); loader.DeleteResource(kv.Key); if (kv.Value.Count == 0) { delList.Add(kv.Key); } } } } for (int i = 0; i < delList.Count; i++) { cacheDict.Remove(delList[i]); } }