Concerning my previous post (thank you for the answer to my previous question),
I have another questions:
What will happen if I have over 20 objects httpwebrequest running in
parallelle?
The memory used will be huge? How can I close the connection (or close
definitively the httpwebrequest?) How can I see the real memory used by the
application?
I trace also the release of objects with the rational software Purify.
If I use objects webproxy and network credential objects, these objects are
not released even it is written webproxy = null and networkcredential= null.
Do you know how to suppress from the memory also?
"Jon Skeet [C# MVP]" wrote:
Marc <Ma**@discussions.microsoft.com> wrote: I am using Visual Studio 2003 with .NET Framework 1.x on XP SP2.
I am executing the following code (see also
http://dturini.blogspot.com/2004/06/...aling-with-som
e.html)
HttpWebRequest wr =
(HttpWebRequest)WebRequest.Create("http://www.microsoft.com/");
using (HttpWebResponse wrp = (HttpWebResponse)wr.GetResponse())
{
using (Stream s = wrp.GetResponseStream())
{
using (StreamReader sr = new StreamReader(s))
{
string st = sr.ReadToEnd();
sr.Close();
s.Close();
}
}
}
There's no need to call sr.Close() or s.Close() when you're using a
"using" block.
wr = null;
You don't need to do that - it'll only make a difference in debug mode.
This call to that list of instructions brings an increase of memory of 4
Mo
(this memory is seen from the task manager concerning this application)
Is-it fixed in the .Net Framework Version 2.0? It seems impossible to
release the memory taken by this list of instructions.
Note that a lot of the handles you talk about in your blog are
*deliberately* not cleaned up - one web request to MS may well be
followed by another, so the connection may be left open, for instance.
Two things about the way you're thinking about memory:
1) The CLR doesn't release the memory back to the operating system
after using it - it reuses it itself instead.
2) Task manager is a notoriously bad way of looking at memory - it just
reports the working set
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too