473,503 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Net Memory and Resource Leaks

My code makes synchronous HttpWebRequest and HttpRebResponse calls. In VS
2003, I am getting memory leaks and event handle leaks. I am closing all
streams and using "using"statements. I have used .Net memory profiler from
Sci Tech to analyze the leaks and they are coming from inside HttpWebRequest
and HttpRebResponse. When I run my code on VS2005, I do not get any leaks.
Is this problem fixed in .Net 1.1 SP1? I may not be able to wait for VS
2005.

Steve Binney

See this blog for a detailed description of the problem:
http://dturini.blogspot.com/2004/06/...with-some.html
Damn! Handle leaks on the CLR!
On the past few days, I'm dealing with some hard to find resource leaks. We
seem to be pushing some areas CLR to their limit. You may say, "hey, how can
you get resource leaks in a garbage collected environment"?.
Well, the simple code below will leak lots of handles.

private void MakeARequest() { HttpWebRequest wr =
(HttpWebRequest)WebRequest.Create("http://www.microsoft.com/");
wr.Proxy = WebProxy.GetDefaultProxy(); wr.Proxy.Credentials =
CredentialCache.DefaultCredentials; 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(); } } } }

Did you see it? It isn't missing a single Close() or Dispose() call, and yet
leaks lots of handles. The biggest the page, the more handles it leaks.
I've been using an evaluation version (10 days remaining...) of the great
SciTech's .NET memory profiler and noticed that the CLR is forgetting to
dispose some (a lot!) ManualResetEvent, Sockets, and some internal Streams
and Readers.
After a while, I found that the culprit are the synchronous HttpWeb(Request,
Response) methods, and, by calling the assynchronous versions, I was able to
reduce it a lot. Even the returned stream, System.Net.ConnectStream have
these problems.
The only problem is when the request throws an Exception, it still leaks
lots of handles, and, by now, it seems that I can do nothing about it...

Steve Binney


Jul 21 '05 #1
0 1852

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

Similar topics

2
3806
by: rtheiss | last post by:
Hi Folks, This is hopefully an easy question. I would like to be able to check available system memory on a WinXP machine from within python. I've checked the docs in the win32 modules, read...
0
983
by: Steve Binney | last post by:
My code makes synchronous HttpWebRequest and HttpRebResponse calls. In VS 2003, I am getting memory leaks and event handle leaks. I am closing all streams and using "using"statements. I have...
0
1609
by: Roz Lee | last post by:
I am trying to access a satellite assembly for a custom culture using Resource Manager. When I use the .getstring method I get the following error message: System.ArgumentException: I can't...
1
1690
by: Abhishek Midya | last post by:
Thankyou for attending to my question. 1. I would like to know how i can display the real time system memory as a graph. 2. How can i query which company and model number does my motherboard...
5
2077
by: Barry Anderberg | last post by:
I'm using a tool by Sci-Tech called the .NET Memory Profiler. We have a massive .NET/C# application here and it has been exhibiting memory leak behavior for some time. Attempting to remedy the...
11
2465
by: ulyses | last post by:
Let's assume I have following file: 2938929384902491233..... 923949919199191919112.... File contains INTs only. What is more they are huge. For example first row in file may contain integer...
15
6689
by: jane | last post by:
We are getting this error during a large large load. 2006-06-03-02.58.31.688266 Instance:sieinst Node:000 PID:1286274(db2agent (SRMW) 0) TID:1 Appid:GAFE423C.P4CE.0671B3070116 database...
0
1572
by: somaskarthic | last post by:
Hi I need to get the system memory (not harddisk storage space) occupied by my c++ application ? Is there any readily available methods to find the memory currently occupied by the application ? ...
5
2745
by: Daniel | last post by:
Hey guys When you hook an event (c# 2.0 syntax): myEvent += MyMethodToFire; You need to also unsubscribe it to avoid a resource leak so that the object it is in gets garbage collected like so...
0
7202
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7084
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
7278
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
5578
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,...
1
5013
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...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1512
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.