diff --git a/csharp/Platform.Collections/Arrays/ArrayPool[T].cs b/csharp/Platform.Collections/Arrays/ArrayPool[T].cs index c1143e4b..57ead451 100644 --- a/csharp/Platform.Collections/Arrays/ArrayPool[T].cs +++ b/csharp/Platform.Collections/Arrays/ArrayPool[T].cs @@ -24,14 +24,26 @@ public class ArrayPool /// /// [ThreadStatic] - private static ArrayPool _threadInstance; + private static WeakReference> _threadInstance; /// /// /// Gets the thread instance value. /// /// /// - internal static ArrayPool ThreadInstance => _threadInstance ?? (_threadInstance = new ArrayPool()); + internal static ArrayPool ThreadInstance + { + get + { + if (_threadInstance?.TryGetTarget(out var instance) == true) + { + return instance; + } + var newInstance = new ArrayPool(); + _threadInstance = new WeakReference>(newInstance); + return newInstance; + } + } private readonly int _maxArraysPerSize; private readonly Dictionary> _pool = new Dictionary>(ArrayPool.DefaultSizesAmount);