public void Clear() { lock (locker){ foreach (KeyValuePair <Tk, CacheElem <Tk, Tv> > pair in map) { CacheElem <Tk, Tv> e = pair.Value; e.previous = null; e.next = null; if (e.data is IDisposable) { ((IDisposable)e.data).Dispose(); } e.data = default(Tv); if (pair.Key is IDisposable) { ((IDisposable)pair.Key).Dispose(); } } map.Clear(); } }