Example #1
0
 private static void Clear(Dictionary <TKey, SparseQueue <TValue> > pools, Action <TKey, TValue> disposeValueCallback)
 {
     foreach (KeyValuePair <TKey, SparseQueue <TValue> > pair in pools)
     {
         SparseQueue <TValue> queue = pair.Value;
         foreach (TValue local in queue)
         {
             disposeValueCallback(pair.Key, local);
         }
         queue.Clear();
         queue.TrimExcess();
     }
 }
Example #2
0
        public void TrimExcess()
        {
            SegmentedList <KeyValuePair <TKey, SparseQueue <TValue> > > list = null;
            object sync = this.sync;

            lock (sync)
            {
                foreach (KeyValuePair <TKey, SparseQueue <TValue> > pair in this.pools)
                {
                    SparseQueue <TValue> collection = pair.Value;
                    if (collection.Any <TValue>())
                    {
                        collection.TrimExcess();
                    }
                    else
                    {
                        if (list == null)
                        {
                            list = new SegmentedList <KeyValuePair <TKey, SparseQueue <TValue> > >();
                        }
                        list.Add(pair);
                    }
                }
                if (list != null)
                {
                    foreach (KeyValuePair <TKey, SparseQueue <TValue> > pair2 in list)
                    {
                        this.pools.Remove(pair2.Key);
                    }
                }
            }
            foreach (KeyValuePair <TKey, SparseQueue <TValue> > pair3 in list)
            {
                pair3.Value.TrimExcess();
            }
        }