Object pooling for .NET
Good objects.
Back in circulation.
Create it once. Use it again. Reservoir keeps your objects ready for the next piece of work, with thread-safe pooling and bounded shared retention. Scoped rentals and opt-in manual rentals also retain objects in per-pool thread-local storage.
dotnet add package Reservoir.NET Standard 2.0-compatible runtimes, with dedicated .NET 8 and .NET 10 assets. Package compatibility.
Try the lifecycle. This illustration starts with a warm pool.
Compare workloads, timings, and allocations.
See the benchmarks and methodologyA short stay in your code.
Rent an object, do your work, and give it back. For synchronous work, a scoped lease handles the return when you leave scope.
- RentReuse an available object, or create one on a miss.
- WorkThe object belongs to you until you return it.
- ReturnReset it for reuse. Discard it if it no longer fits.
using Reservoir;
using var lease = ListPool<int>.Shared
.RentScoped(out List<int> numbers);
numbers.Add(42);
Consume(numbers);
// Leaving scope returns the list.
// The next renter gets an empty one.
Crossing an await? Use Rent / Return with try / finally.
Your everyday objects.
Already covered.
Built-in pools for collections and text. Rent them empty, return them for reuse, and set limits on what stays cached.
Browse collection and text poolsList<T>Dictionary<TKey, TValue>HashSet<T>Queue<T>Stack<T>StringBuilderAlso included: CancellationTokenSource pooling.
Something of your own? Define a creation and reset policy.