Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpWebRequest has no close method?

Tags:

c#

.net

.net-3.5

I am very surprised to see HttpWebRequest has no close method, but its counter-part HttpWebResponse has. It makes me a little bit confused and inconvenient. :-)

So, we only need to call Close on response and no need to treat with request? My concern is about leaks and better resource usage efficiency. I am using VSTS2008 + C# + .Net 3.5.

like image 853
George2 Avatar asked Aug 02 '09 09:08

George2


1 Answers

Yes, you just need to call it on the response object.

A request does absolutely nothing on its own. It doesn't open up a socket or something. It just holds some data and you can just ignore it and throw it away if you don't need it (it's a pure managed resource and garbage collector will take care of it). Actual stuff happens after one of the GetResponse methods is called.

like image 56
mmx Avatar answered Oct 18 '22 18:10

mmx