I am using a httpwebrequest, and am disposing of the response stream. Is there a correct method of disposing of the httpwebrequest, as it does not contain a close or dispose method?
+2
A:
HttpWebRequest does not implement IDisposable so it does not require disposing. just set the httprequest object to null once your done with it.
Hope it helps
Why set to null? Just letting it go out of scope is enough for the GC to pick it up.....
Mark Brackett
2009-04-04 03:40:54
+7
A:
If the class had special disposal requirements, it would have implemented IDisposable. Since it doesn't implement IDisposable, you may assume there's nothing special you need to do.
John Saunders
2009-04-04 03:31:43
A:
httpwebRequest doesn't implement IDisposable since it can create a Stream, which does implement IDisposable. As such, you shouldnt worry about disposing it.
If you are worried though, you may want to use WebClient, which is IDisposable:
using (WebClient c = new WebClient())
{
using (Stream stream = c.OpenRead(url))
{
//
}
}
Joshua
2009-04-04 03:36:27