diff --git a/VContainer/Assets/VContainer/Runtime/Internal/CappedArrayPool.cs b/VContainer/Assets/VContainer/Runtime/Internal/CappedArrayPool.cs index b6ba85a0..13d7d56d 100644 --- a/VContainer/Assets/VContainer/Runtime/Internal/CappedArrayPool.cs +++ b/VContainer/Assets/VContainer/Runtime/Internal/CappedArrayPool.cs @@ -62,6 +62,7 @@ public void Return(T[] array) var i = array.Length - 1; lock (syncRoot) { + Array.Clear(array, 0, array.Length); if (tails[i] > 0) tails[i] -= 1; } diff --git a/VContainer/Assets/VContainer/Tests/CappedArrayPoolTest.cs b/VContainer/Assets/VContainer/Tests/CappedArrayPoolTest.cs index cbccf8e8..3baf0d92 100644 --- a/VContainer/Assets/VContainer/Tests/CappedArrayPoolTest.cs +++ b/VContainer/Assets/VContainer/Tests/CappedArrayPoolTest.cs @@ -7,14 +7,26 @@ namespace VContainer.Tests public class CappedArrayPoolTest { [Test] - public void RentWithExpandBucket() + public void Return_ClearElements() { - var cappedArrayPool = new CappedArrayPool(8); + var pool = new CappedArrayPool(8); + var a = pool.Rent(4); + a[0] = new object(); + a[3] = new object(); + pool.Return(a); + Assert.That(a[0], Is.Null); + Assert.That(a[3], Is.Null); + } + + [Test] + public void Rent_ExpandBucket() + { + var pool = new CappedArrayPool(8); Assert.DoesNotThrow(() => { for (var i = 1; i < CappedArrayPool.InitialBucketSize * 2; i++) { - cappedArrayPool.Rent(1); + pool.Rent(1); } }); }