473,386 Members | 1,764 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,386 software developers and data experts.

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 1837

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

Similar topics

2
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.