ImageBufferPool Class

The settings of the process-wide pool of the buffers the library rents for pixels, decoders, encoders and scratch memory.

public static class ImageBufferPool

Remarks

A disposed image, or a finished operation, returns its buffers to the pool, which keeps some of them for the next rentals instead of leaving them to the garbage collector. Retention is bounded per buffer size and in total bytes (ImageBufferPool.MaxRetainedBytes, 32 MiB by default), and buffers larger than 8 MiB are never retained. The retained buffers are not part of any ImageResourceLimits.MaxLiveAllocationBytes budget.

In a memory-constrained container, lower ImageBufferPool.MaxRetainedBytes, or set it to 0 to disable retention: every buffer then goes back to the garbage collector when it is returned. The settings never change the output of an operation. This type is thread-safe.

Properties

NameDescription
MaxRetainedBytesGets or sets the maximum number of bytes the pool retains across all buffer sizes. Defaults to ImageBufferPool.DefaultMaxRetainedBytes; 0 disables retention.
RetainedBytesGets the number of bytes the pool currently retains.

MaxRetainedBytes

ImageBufferPool.cs

Gets or sets the maximum number of bytes the pool retains across all buffer sizes. Defaults to ImageBufferPool.DefaultMaxRetainedBytes; 0 disables retention.

public static long MaxRetainedBytes { get; set; }

Property value

long

Exceptions

ArgumentOutOfRangeException
The value is negative.

Remarks

Lowering the value releases retained buffers immediately, until the retained bytes fit.

RetainedBytes

ImageBufferPool.cs

Gets the number of bytes the pool currently retains.

public static long RetainedBytes { get; }

Property value

long

Methods

NameDescription
Trim()Releases every retained buffer to the garbage collector. Buffers that are in use are not affected.

Releases every retained buffer to the garbage collector. Buffers that are in use are not affected.

public static void Trim()

Constants

NameDescription
DefaultMaxRetainedBytesThe default value of ImageBufferPool.MaxRetainedBytes (32 MiB).

DefaultMaxRetainedBytes

The default value of ImageBufferPool.MaxRetainedBytes (32 MiB).

public const long DefaultMaxRetainedBytes = 33554432L