예제 #1
0
 public static void Cull()
 {
     lock ( Sync )
     {
         DynamicFields.RemoveCollectedEntries();
     }
 }
        private static ClassAnnotation GetOrCreateAnnotation(object key)
        {
            _annotations.RemoveCollectedEntries();

            ClassAnnotation annotation;

            if (!_annotations.TryGetValue(key, out annotation))
            {
                lock (_annotations)
                {
                    if (!_annotations.TryGetValue(key, out annotation))
                    {
                        annotation = new ClassAnnotation(key);
                        _annotations.Add(key, annotation);
                    }
                }
            }

            return(annotation);
        }
예제 #3
0
        public void TestRemoveDeadItem()
        {
            WeakDictionary<KeyObject, int> weakDict = new WeakDictionary<KeyObject, int>(comparer, 5);
            for (int i = 0; i < 5; i++)
            {
                AddAnItem(weakDict, i);
            }

            // Force gc to collect dead items
            GC.Collect();
            if (GC.WaitForFullGCComplete() == GCNotificationStatus.Succeeded)
            {
                Assert.AreEqual(5, weakDict.Count);

                // Since the referesh interval is 5, so when adding the sixth item, it should clear the 5 dead items first.
                weakDict.RemoveCollectedEntries();
                Assert.AreEqual(0, weakDict.Count);
            }
        }
예제 #4
0
        private void RetireInfoCard([NotNull] InfoCard infoCard)
        {
            if (infoCard == null)
            {
                throw new ArgumentNullException("infoCard");
            }

            infoCard.Closed         -= OnInfoCardClosed;
            infoCard.SubjectChanged -= OnInfoCardSubjectChanged;

            var infoCardSubject = infoCard.Subject;

            if (infoCardSubject != null)
            {
                _infoCardCache.Remove(infoCard.Subject);
            }

            _infoCardCache.RemoveCollectedEntries();

            infoCard.ClearValue(InfoCard.SubjectProperty);
        }
예제 #5
0
        public void TestRemoveDeadItem()
        {
            WeakDictionary<KeyObject, int> weakDict = new WeakDictionary<KeyObject, int>(comparer, 5);
            for (int i = 0; i < 5; i++)
            {
                AddAnItem(weakDict, i);
            }

            // Force gc to collect dead items
            GC.Collect();
            if (GC.WaitForFullGCComplete() == GCNotificationStatus.Succeeded)
            {
                Assert.AreEqual(5, weakDict.Count);

                // Since the referesh interval is 5, so when adding the sixth item, it should clear the 5 dead items first.
                weakDict.RemoveCollectedEntries();
                Assert.AreEqual(0, weakDict.Count);
            }
        }