C#: “Using” Statements with HttpWebRequests/HttpWebResponses

前端 未结 3 364
时光说笑
时光说笑 2020-12-16 11:26

Jon Skeet made a comment (via Twitter) on my SOApiDotNet code (a .NET library for the pre-alpha Stack Overflow API):

@maximz2005 One thing I\'ve noticed

3条回答
  •  误落风尘
    2020-12-16 12:09

    In order to prevent memory leaks you should call Dispose on every object that implements IDisposable. You can ensure that the Dispose method in called by using the using keyword (no pun intended) as it is just a syntactic sugar for try-finally block.

提交回复
热议问题