diff --git a/src/ObservableCollections/Internal/ResizableArray.cs b/src/ObservableCollections/Internal/ResizableArray.cs index d767a88..ba032d0 100644 --- a/src/ObservableCollections/Internal/ResizableArray.cs +++ b/src/ObservableCollections/Internal/ResizableArray.cs @@ -33,8 +33,10 @@ public void Add(T item) [MethodImpl(MethodImplOptions.NoInlining)] void EnsureCapacity() { - var newArray = array.AsSpan().ToArray(); - ArrayPool.Shared.Return(array!, RuntimeHelpersEx.IsReferenceOrContainsReferences()); + var oldArray = array!; + var newArray = ArrayPool.Shared.Rent(oldArray.Length * 2); + Array.Copy(oldArray, newArray, oldArray.Length); + ArrayPool.Shared.Return(oldArray, RuntimeHelpersEx.IsReferenceOrContainsReferences()); array = newArray; }