From bd99479318238982fa6ba6546553beea5fb5b23a Mon Sep 17 00:00:00 2001 From: konard Date: Sat, 13 Sep 2025 20:39:46 +0300 Subject: [PATCH 1/3] Initial commit with task details for issue #99 Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: https://github.com/linksplatform/Collections/issues/99 --- CLAUDE.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 00000000..fd0d9909 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,5 @@ +Issue to solve: https://github.com/linksplatform/Collections/issues/99 +Your prepared branch: issue-99-57f43aa3 +Your prepared working directory: /tmp/gh-issue-solver-1757785168074 + +Proceed. \ No newline at end of file From 67001580360cdf9a406b5832056e49b886826700 Mon Sep 17 00:00:00 2001 From: konard Date: Sat, 13 Sep 2025 20:44:32 +0300 Subject: [PATCH 2/3] Replace strong reference with WeakReference in ArrayPool ThreadStatic field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change prevents memory leaks by allowing the garbage collector to collect ArrayPool instances when memory pressure is high, instead of keeping them alive for the entire thread lifetime. Fixes #99 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../Platform.Collections/Arrays/ArrayPool[T].cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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); From 015fa6c14bebcdad1c6489999dd9353bb657b5fe Mon Sep 17 00:00:00 2001 From: konard Date: Sat, 13 Sep 2025 20:45:11 +0300 Subject: [PATCH 3/3] Remove CLAUDE.md - Claude command completed --- CLAUDE.md | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md deleted file mode 100644 index fd0d9909..00000000 --- a/CLAUDE.md +++ /dev/null @@ -1,5 +0,0 @@ -Issue to solve: https://github.com/linksplatform/Collections/issues/99 -Your prepared branch: issue-99-57f43aa3 -Your prepared working directory: /tmp/gh-issue-solver-1757785168074 - -Proceed. \ No newline at end of file