Esempio n. 1
0
 private static void RemoveFreedObjects()
 {
     while (!finalExit)
     {
         List <WeakKeyedItem> list;
         lock (collections) {
             list = new List <WeakKeyedItem>(collections);
         }
         List <WeakKeyedItem> listToRemove = new List <WeakKeyedItem>();
         foreach (WeakKeyedItem pointer in list)
         {
             WeakKeyedCollection collection = pointer.Target as WeakKeyedCollection;
             if (collection == null)
             {
                 listToRemove.Add(pointer);
                 continue;
             }
             foreach (WeakKeyedItem item in collection.dictionary.Keys)
             {
                 if (item.Target == null)
                 {
                     WeakKeyedItem dummy;
                     collection.dictionary.TryRemove(item, out dummy);
                 }
             }
         }
         if (listToRemove.Count > 0)
         {
             lock (collections) {
                 foreach (WeakKeyedItem item in listToRemove)
                 {
                     collections.Remove(item);
                 }
             }
         }
         Thread.Sleep(1000);
     }
 }