Beispiel #1
0
        public virtual void Dispose()
        {
            if (_disposed)
            {
                return;
            }
            lock (this)
            {
                if (_disposed)
                {
                    return;
                }

                _cts.Cancel();
                _disposed = true;
                CleanThreadLocalState();
                ThreadLocalCleanup.ReleaseThreadLocalState -= CleanThreadLocalState;
                _nativeMemoryCleaner.Dispose();
                _nativeMemoryCleaner = null;

                foreach (var kvp in EnumerateAllThreadContexts())
                {
                    kvp.Dispose();
                }
                _contextStacksByThreadId?.Clear();
                _contextStacksByThreadId = null;
                _threadIds = Array.Empty <ThreadIdHolder>();
            }
        }
Beispiel #2
0
 protected JsonContextPoolBase()
 {
     _contextPool = new ThreadLocal <ContextStack>(() => _contextStackPool.Allocate(), trackAllValues: true);
     ThreadLocalCleanup.ReleaseThreadLocalState += CleanThreadLocalState;
     _nativeMemoryCleaner = new NativeMemoryCleaner <ContextStack, T>(_contextPool, LowMemoryFlag, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
     LowMemoryNotification.Instance?.RegisterLowMemoryHandler(this);
 }
Beispiel #3
0
 protected JsonContextPoolBase()
 {
     ThreadLocalCleanup.ReleaseThreadLocalState += CleanThreadLocalState;
     _nativeMemoryCleaner = new NativeMemoryCleaner <ContextStack, T>(this, s => ((JsonContextPoolBase <T>)s).EnumerateAllThreadContexts().ToList(),
                                                                      LowMemoryFlag, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
     LowMemoryNotification.Instance?.RegisterLowMemoryHandler(this);
 }