Table of Contents

Struct Lease<T>

Namespace
Enderlook.Pools
Assembly
Enderlook.Pools.dll

Represent a pooled value.
When Dispose() is executed, the value is returned to the pool.

public struct Lease<T> : IDisposable

Type Parameters

T

Type of value to pool.

Implements
Inherited Members

Remarks

This type doesn't provide any double-dipose, default value or use after dispose safety.
This is to ensure the highest performance of the type.

Users must ensure:

  • The instance is disposed exactly once.
  • The field Value is not used after disposing.
  • The instance is always obtained from a pool rather than using default (default(Lease<T>)) or calling its parameterless constructor.
  • Treat the instance under move-semantics. This particularly important if T is a mutable value type, as mutations in Value would differ between copies.

Fields

Value

Value that is being rented.

public T Value

Field Value

T

Remarks

This is a field so when T is a mutable value type it can be mutated.
However, it's not intended for users to replace the value with another one never.

Methods

Dispose()

Returns the value to the pool.

public readonly void Dispose()

Remarks

This method must be executed exactly once per instance.