예제 #1
0
        public void ArrayMemoryLifetime()
        {
            Memory <byte> copyStoredForLater;
            var           owner = new OwnedArray <byte>(1024);

            try {
                Memory <byte> memory      = owner.Memory;
                Memory <byte> memorySlice = memory.Slice(10);
                copyStoredForLater = memorySlice;
                var r = memorySlice.Reserve();
                try {                                                 // increments the "outstanding span" refcount
                    Assert.Throws <InvalidOperationException>(() => { // memory is reserved; cannot dispose
                        owner.Dispose();
                    });
                    Assert.Throws <ObjectDisposedException>(() => {
                        Span <byte> span = memorySlice.Span;
                        span[0]          = 255;
                    });
                }
                finally {
                    Assert.Throws <ObjectDisposedException>(() => {
                        r.Dispose(); // releases the refcount
                    });
                }
            }
            finally {
                Assert.Throws <InvalidOperationException>(() => {
                    owner.Dispose();
                });
            }
            Assert.Throws <ObjectDisposedException>(() => { // manager is disposed
                var span = copyStoredForLater.Span;
            });
        }
예제 #2
0
        public void Dispose()
        {
            var headersArray = _headersMemory.Array;

            _headersMemory.Dispose();
            ArrayPool <byte> .Shared.Return(headersArray);

            var bodyArray = _bodyMemory.Array;

            _bodyMemory.Dispose();
            ArrayPool <byte> .Shared.Return(bodyArray);
        }