Closing streams, always necessary? .net

后端 未结 4 1282
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-17 08:54

Is it always necessary to close streams or, because .net is managed code, will it be closed automatically as soon as it drops out of scope (assuming there are no exceptions

4条回答
  •  广开言路
    2021-01-17 09:19

    .Net's GC is very... lazy. Just because a reference has been lost doesn't mean it's immediately swept up, crushed and sent to the landfill. It's always a good idea to close open resources and to dispose of objects that implement IDisposable for that very reason.

提交回复
热议问题