diff --git a/src/Bundles/ValueCollections/ValueAppendList.cs b/src/Bundles/ValueCollections/ValueAppendList.cs
index 6899892..4f633e3 100644
--- a/src/Bundles/ValueCollections/ValueAppendList.cs
+++ b/src/Bundles/ValueCollections/ValueAppendList.cs
@@ -2,18 +2,20 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
+using System;
using System.Buffers;
namespace Bundles.ValueCollections;
///
-/// A value-type list type that can only be modified by appending, never by removing.
+/// A value-type list type that can only be modified by appending, never by removing. Use after disposal is undefined behaviour.
///
/// The element type controlled by this list.
-public partial record struct ValueAppendList
+public partial record struct ValueAppendList : IDisposable
{
private T[] buffer;
private int index;
+ private bool disposed;
///
/// Gets a readonly reference to the element at the specified index.
@@ -51,6 +53,16 @@ public ref readonly T Add(T value)
public readonly Enumerator GetEnumerator()
=> new(this);
+ public void Dispose()
+ {
+ if (!this.disposed && typeof(T).IsPrimitive)
+ {
+ ArrayPool.Shared.Return(this.buffer);
+ }
+
+ this.disposed = true;
+ }
+
private void ResizeBuffer()
{
int newLength = this.buffer.Length * 2;