Skip to content

Commit

Permalink
Prevent acquiring from disposed pool and dispose objects when releasi…
Browse files Browse the repository at this point in the history
…ng to disposed pool
  • Loading branch information
Exanite committed Jan 21, 2025
1 parent 2aecfbc commit 6a3b55a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Pooling/Pool.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Exanite.Core.Runtime;
using Exanite.Core.Utilities;

namespace Exanite.Core.Pooling
{
Expand Down Expand Up @@ -84,6 +85,8 @@ public Handle Acquire(out T value)

public T Acquire()
{
AssertUtility.IsFalse(IsDisposed, "Pool has been disposed");

if (values.Count == 0)
{
values.Enqueue(create());
Expand All @@ -101,7 +104,7 @@ public void Release(T element)
onRelease.Invoke(element);

UpdateUsageInfo();
if (usageInfo.InactiveCount < usageInfo.MaxInactive)
if (!IsDisposed && usageInfo.InactiveCount < usageInfo.MaxInactive)
{
values.Enqueue(element);
}
Expand Down

0 comments on commit 6a3b55a

Please sign in to comment.