473,403 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

HttpWebRequest Memory release

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();
}
}
}
wr = null;

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.
Nov 16 '05 #1
3 3309
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
Nov 16 '05 #2
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

Nov 16 '05 #3
Marc <Ma**@discussions.microsoft.com> wrote:
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?
If they're going to the same host, they probably won't actually run in
parallel - there's a limit (in machine.config) of the number of web
requests going to the same host.
The memory used will be huge?
Not necessarily. Bear in mind that not all the memory you're seeing
being allocated is necessarily *used*. The CLR may choose to request
4MB from the OS, even if it doesn't need all of it yet.
How can I close the connection (or close
definitively the httpwebrequest?)
I don't know any way of doing that, although it may be possible.
How can I see the real memory used by the application?
Use a profiler.
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?


They're probably cached somewhere too - presumably to identify the
connection in the cache.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Tron Thomas | last post by:
Given the following information about memory management in C++: ----- The c-runtime dynamic memory manager (and most other commercial memory managers) has issues with fragmentation similar to a...
4
by: Franklin Lee | last post by:
Hi All, I use new to allocate some memory,even I doesn't use delete to release them. When my Application exit, OS will release them. Am I right? If I'm right, how about Thread especally on...
16
by: thomas peter | last post by:
I am building a precache engine... one that request over 100 pages on an remote server to cache them remotely... can i use the HttpWebRequest and WebResponse classes for this? or must i use the...
0
by: student | last post by:
I have an object created called objM_message. I want to serialize it as xml and place the xml in my HttpWebRequest.GetRequestStream. But the line resp = req.GetResponse doesnt return any...
5
by: Rodrigue | last post by:
I have code where I populate a data table using visual basic.net code. I call the clear method on the table but it does not seem to release the memory. When I populate the table again, the memory...
8
by: Lauren the Ravishing | last post by:
Hi, In ASP, is it absolutely necessary to set an object to Nothing after being used? set myObj = server.createObject("myDLL.myClass") call myObj.useClass set myObj = Nothing <--- can I...
2
by: Epetruk | last post by:
Hello, I have a problem where an application I am working on throws an OutOfMemoryException when I run it in Release mode, whereas it doesn't do this when I am running in Debug. The...
0
by: Morgan Cheng | last post by:
In the doc http://msdn2.microsoft.com/en-us/library/system.net.httpwebrequest.timeout.aspx, it reads, "A Domain Name System (DNS) query may take up to 15 seconds to return or time out. If your...
4
by: JVNewbie | last post by:
I'm attempting to test an aspx module that will receive XML data from a web service (the receiver module). I want to be able to test this portion before attempting to create the Web Service that will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.