public static void Clear_EmptyTable()
        {
            var cwt = new ConditionalWeakTable <object, object>();

            cwt.Clear(); // no exception
            cwt.Clear();
        }
Пример #2
0
            internal static void RemoveAllEventHandlers(Action <EventRegistrationToken> removeMethod)
            {
                object instanceKey = WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.GetInstanceKey(removeMethod);
                List <EventRegistrationToken> registrationTokenList = new List <EventRegistrationToken>();

                WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.s_eventCacheRWLock.AcquireReaderLock(-1);
                try
                {
                    WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.TokenListCount tokenListCount;
                    ConditionalWeakTable <object, WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.EventRegistrationTokenListWithCount> tokenTableNoCreate = WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.GetEventRegistrationTokenTableNoCreate(instanceKey, removeMethod, out tokenListCount);
                    if (tokenTableNoCreate == null)
                    {
                        return;
                    }
                    lock (tokenTableNoCreate)
                    {
                        foreach (WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.EventRegistrationTokenListWithCount item_0 in (IEnumerable <WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.EventRegistrationTokenListWithCount>)tokenTableNoCreate.Values)
                        {
                            item_0.CopyTo(registrationTokenList);
                        }
                        tokenTableNoCreate.Clear();
                    }
                }
                finally
                {
                    WindowsRuntimeMarshal.NativeOrStaticEventRegistrationImpl.s_eventCacheRWLock.ReleaseReaderLock();
                }
                WindowsRuntimeMarshal.CallRemoveMethods(removeMethod, registrationTokenList);
            }
Пример #3
0
 public static void Clear <TKey, TValue>(
     this ConditionalWeakTable <TKey, TValue> table)
     where TKey : class
     where TValue : class
 {
     table.Clear();
 }
        public static void GetEnumerator_ItemsClearedAfterGetEnumeratorNotIncluded()
        {
            var cwt        = new ConditionalWeakTable <object, object>();
            var enumerable = (IEnumerable <KeyValuePair <object, object> >)cwt;

            object key1 = new object(), key2 = new object(), value1 = new object(), value2 = new object();

            cwt.Add(key1, value1);
            cwt.Add(key2, value2);
            IEnumerator <KeyValuePair <object, object> > enumerator1 = enumerable.GetEnumerator();

            cwt.Clear();
            IEnumerator <KeyValuePair <object, object> > enumerator2 = enumerable.GetEnumerator();

            Assert.False(enumerator1.MoveNext());
            Assert.False(enumerator2.MoveNext());

            enumerator1.Dispose();
            enumerator2.Dispose();

            GC.KeepAlive(key1);
            GC.KeepAlive(key2);
            GC.KeepAlive(value1);
            GC.KeepAlive(value2);
        }
 private static void FinalizeGlobalPool()
 {
     foreach (var client in _httpClientsPool)
     {
         client.Value.Dispose();
     }
     _httpClientsPool.Clear();
 }
Пример #6
0
        /// <summary>
        /// Clean up any cached providers.
        /// </summary>
        void IDisposable.Dispose()
        {
            foreach ((Assembly _, MetadataReaderProvider? provider) in _metadataCache)
            {
                provider?.Dispose();
            }

            _metadataCache.Clear();
        }
        /// <summary>
        /// Clean up any cached providers.
        /// </summary>
        void IDisposable.Dispose()
        {
#pragma warning disable CS8619 // TODO-NULLABLE: Compiler complains about `provider`
            foreach ((Assembly _, MetadataReaderProvider? provider) in _metadataCache)
#pragma warning restore CS8619
            {
                provider?.Dispose();
            }

            _metadataCache.Clear();
        }
        private void ClearCompilationsWithAnalyzersCache()
        {
            // we basically eagarly clear the cache on some known changes
            // to let CompilationWithAnalyzer go.

            // we create new conditional weak table every time netstandard as that's the only way it has to clear it.
#if NETSTANDARD
            _projectCompilationsWithAnalyzers = new ConditionalWeakTable <Project, CompilationWithAnalyzers?>();
#else
            _projectCompilationsWithAnalyzers.Clear();
#endif
        }
 static HttpClientHandler()
 {
     _httpClientsPool = new ConditionalWeakTable <Uri, HttpClientHandler>();
     AppDomain.CurrentDomain.ProcessExit +=
         (sender, eventArgs) =>
     {
         foreach (var client in _httpClientsPool)
         {
             client.Value.Dispose();
         }
         _httpClientsPool.Clear();
     };
 }
        public static void Clear_AddThenEmptyRepeatedly_ItemsRemoved()
        {
            var    cwt = new ConditionalWeakTable <object, object>();
            object key = new object(), value = new object();
            object result;

            for (int i = 0; i < 3; i++)
            {
                cwt.Add(key, value);

                Assert.True(cwt.TryGetValue(key, out result));
                Assert.Same(value, result);

                cwt.Clear();

                Assert.False(cwt.TryGetValue(key, out result));
                Assert.Null(result);
            }
        }
        public static void Clear_AddMany_Clear_AllItemsRemoved()
        {
            var cwt = new ConditionalWeakTable <object, object>();

            object[] keys   = Enumerable.Range(0, 33).Select(_ => new object()).ToArray();
            object[] values = Enumerable.Range(0, keys.Length).Select(_ => new object()).ToArray();
            for (int i = 0; i < keys.Length; i++)
            {
                cwt.Add(keys[i], values[i]);
            }

            Assert.Equal(keys.Length, ((IEnumerable <KeyValuePair <object, object> >)cwt).Count());

            cwt.Clear();

            Assert.Equal(0, ((IEnumerable <KeyValuePair <object, object> >)cwt).Count());

            GC.KeepAlive(keys);
            GC.KeepAlive(values);
        }
Пример #12
0
 internal void clear()
 {
     table.Clear();
 }
Пример #13
0
 public void LowMemory()
 {
     TermsCachePerReader.Clear();
 }
 internal override void Evict()
 {
     _textures.Clear();
 }
 public override void Dispose()
 {
     _corInfoImpls?.Clear();
 }
Пример #16
0
 public void LowMemory(LowMemorySeverity lowMemorySeverity)
 {
     TermsCachePerReader.Clear();
 }
 public void Clear()
 {
     _table.Clear();
 }