internal void ReturnBlocks()

in src/Elastic.Transport/Components/Providers/RecyclableMemoryStreamManager.cs [448:479]


	internal void ReturnBlocks(ICollection<byte[]> blocks, string tag)
	{
		if (blocks == null) throw new ArgumentNullException(nameof(blocks));

		var bytesToReturn = blocks.Count * BlockSize;
		Interlocked.Add(ref _smallPoolInUseSize, -bytesToReturn);

		foreach (var block in blocks)
		{
			if (block == null || block.Length != BlockSize)
				throw new ArgumentException("blocks contains buffers that are not BlockSize in length");
		}

		foreach (var block in blocks)
		{
			if (MaximumFreeSmallPoolBytes == 0 || SmallPoolFreeSize < MaximumFreeSmallPoolBytes)
			{
				Interlocked.Add(ref _smallPoolFreeSize, BlockSize);
				_smallPool.Push(block);
			}
			else
			{
				EventsWriter.MemoryStreamDiscardBuffer(Events.MemoryStreamBufferType.Small, tag,
					Events.MemoryStreamDiscardReason.EnoughFree);
				ReportBlockDiscarded();
				break;
			}
		}

		ReportUsageReport(_smallPoolInUseSize, _smallPoolFreeSize, LargePoolInUseSize,
			LargePoolFreeSize);
	}