Dispose() public method

public Dispose ( ) : void
return void
Exemplo n.º 1
0
        protected override void Dispose(bool disposing)
        {
            try
            {
                PurgeBuffers(disposing);
            }
            finally
            {
                // Close the underlying stream even if PurgeBuffers threw.
                // Stream.Close() may throw here (may or may not be due to the same error).
                // In this case, we still need to clean up internal resources, hence the inner finally blocks.
                try
                {
                    if (disposing && !_leaveOpen)
                    {
                        _stream?.Dispose();
                    }
                }
                finally
                {
                    _stream = null;

                    try
                    {
                        _deflater?.Dispose();
                        _inflater?.Dispose();
                    }
                    finally
                    {
                        _deflater = null;
                        _inflater = null;

                        byte[] buffer = _buffer;
                        if (buffer != null)
                        {
                            _buffer = null;
                            if (!AsyncOperationIsActive)
                            {
                                ArrayPool <byte> .Shared.Return(buffer);
                            }
                        }

                        base.Dispose(disposing);
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected override void Dispose(bool disposing)
        {
            try
            {
                PurgeBuffers(disposing);
            }
            finally
            {
                // Close the underlying stream even if PurgeBuffers threw.
                // Stream.Close() may throw here (may or may not be due to the same error).
                // In this case, we still need to clean up internal resources, hence the inner finally blocks.
                try
                {
                    if (disposing && !_leaveOpen && _stream != null)
                    {
                        _stream.Dispose();
                    }
                }
                finally
                {
                    _stream = null;

                    try
                    {
                        if (_deflater != null)
                        {
                            _deflater.Dispose();
                        }
                        if (_inflater != null)
                        {
                            _inflater.Dispose();
                        }
                    }
                    finally
                    {
                        if (_buffer != null)
                        {
                            ArrayPool <byte> .Shared.Return(_buffer, clearArray : true);
                        }
                        _buffer   = null;
                        _deflater = null;
                        _inflater = null;
                        base.Dispose(disposing);
                    }
                }
            }
        }