release method

  1. @override
void release(
  1. Uint8List buffer
)
override

Returns buffer to the pool for reuse.

Implementation

@override
void release(Uint8List buffer) {
  final cap = buffer.length;
  if (cap == 0) return;
  // Only retain power-of-two buffers (what rent() creates).
  if ((cap & (cap - 1)) != 0) return;

  // If the pool is configured to keep nothing, avoid allocating a bucket.
  if (maxPerBucket == 0) return;

  final list = _buckets.putIfAbsent(cap, () => <Uint8List>[]);
  if (list.length >= maxPerBucket) return;
  list.add(buffer);
}