internal void ReturnBlock()

in src/RecyclableMemoryStreamManager.cs [615:642]


        internal void ReturnBlock(byte[] block, Guid id, string tag)
        {
            var bytesToReturn = this.BlockSize;
            Interlocked.Add(ref this.smallPoolInUseSize, -bytesToReturn);

            if (block == null)
            {
                throw new ArgumentNullException(nameof(block));
            }

            if (block.Length != this.BlockSize)
            {
                throw new ArgumentException($"{nameof(block)} is not not {nameof(BlockSize)} in length.");
            }

            if (this.MaximumFreeSmallPoolBytes == 0 || this.SmallPoolFreeSize < this.MaximumFreeSmallPoolBytes)
            {
                Interlocked.Add(ref this.smallPoolFreeSize, this.BlockSize);
                this.smallPool.Push(block);
            }
            else
            {
                ReportBufferDiscarded(id, tag, Events.MemoryStreamBufferType.Small, Events.MemoryStreamDiscardReason.EnoughFree);
            }

            ReportUsageReport(this.smallPoolInUseSize, this.smallPoolFreeSize, this.LargePoolInUseSize,
                              this.LargePoolFreeSize);
        }