I have a .Net Framework # 4.0 application that makes a large number of web requests using the WebRequest / WebResponse classes, since I see that it has a memory leak (or maybe I'm doing something wrong) I wrote a little A small application that demonstrates this:
class Program { public static void Main(string[] args) { while(true) { var webRequest = (HttpWebRequest)WebRequest.Create("http://www.gooogle.com"); Init(webRequest); using (var webResponse = (HttpWebResponse)webRequest.GetResponse()) { var responseStream = webResponse.GetResponseStream(); responseStream.ReadTimeout = 30; var streamReader = new StreamReader(responseStream, Encoding.UTF8); var page = streamReader.ReadToEnd(); streamReader.Close(); streamReader.Dispose(); responseStream.Close(); responseStream.Dispose(); webResponse.Close(); Console.WriteLine("Done");
The only solution I came across is using GC.Collect () (not noted in the example). All objects are located, all threads are closed, am I missing something?
I found something, but I donโt understand the reason, if I minimize the console, the memory usage will decrease and it looks OK, which may be the reason that there is a problem with Conosole or WinForm, how can I fix it?
Robob
source share