MemoryStream must be explicitely be disposed?

后端 未结 4 2086
别跟我提以往
别跟我提以往 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条回答
  •  梦毁少年i
    2020-12-19 07:59

    MemoryStream implements IDisposable so when possible, use a using statement.

    When that isn't feasible, make it a try/catch/finally block.

    In cases when you need to let the object pass out of the scope of your code (when using or try/catch/finally won't work), it becomes the responsibility of the caller to implement the explicit disposal.

提交回复
热议问题