MemoryStream must be explicitely be disposed?

后端 未结 4 2070
别跟我提以往
别跟我提以往 2020-12-19 07:20

As MemoryStream is an unmanaged resource does it always have to be disposed?

Given:

1) A method is invoked.
2) A MemoryStream object is created (Mem         


        
4条回答
  •  囚心锁ツ
    2020-12-19 08:14

    Any type that implements IDisposable should have Dispose called on it either explicitly via a try/catch/finally block or via the using statement.

    There are cases such as this where technically the MemoryStream does not need disposed, however to honor the interface and protect yourself from changes downstream Dispose should still be called.

提交回复
热议问题