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>(); } }
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); }
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); }