diff --git a/VContainer/Assets/VContainer/Runtime/Internal/CappedArrayPool.cs b/VContainer/Assets/VContainer/Runtime/Internal/CappedArrayPool.cs index 13d7d56d..dbdb4b14 100644 --- a/VContainer/Assets/VContainer/Runtime/Internal/CappedArrayPool.cs +++ b/VContainer/Assets/VContainer/Runtime/Internal/CappedArrayPool.cs @@ -24,7 +24,7 @@ internal CappedArrayPool(int maxLength) { buckets[i][j] = new T[arrayLength]; } - tails[i] = buckets[i].Length - 1; + tails[i] = 0; } } @@ -48,7 +48,12 @@ public T[] Rent(int length) buckets[i] = bucket; } - var result = bucket[tail] ?? new T[length]; + if (bucket[tail] == null) + { + bucket[tail] = new T[length]; + } + + var result = bucket[tail]; tails[i] += 1; return result; }