hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Suladna <sula...@yahoo.com>
Subject My HttpClient gives me a memory leak
Date Thu, 04 Sep 2008 07:40:46 GMT
Hi
 
I have used the following tutorial to bring html-code from websites to my java program:
 
http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/examples/org/apache/http/examples/client/ClientExecuteDirect.java
 
The websites which I connect to all start with www.xxxxxxxxx.se *  but they have different
endings.
 
So I start by making one HttpHost and defining a HttpEntity and HttpRespons
 
final HttpHost target = new HttpHost("www.xxxxxxx.se", 80, "http");
HttpEntity entity = null;
HttpResponse rsp = null;

 
After that I use a loop to connect to each subsite. This is what I write in the loop:
 
HttpRequest req = createRequest(urlEnding);
rsp = client.execute(target, req);
entity = rsp.getEntity();
String[] line = EntityUtils.toString(entity).split("\n"); //this info is used by the program
if (entity != null){
entity.consumeContent(); 
}
 
It basically works fine, but the problem is that I get a memory leak.. after having brought
the code from a few hundred websites I get a java.lang.OutOfMemoryError: Java heap space.
Is there anything I can do in the loop except entity.consumeConent() to prevent this from
happening?
 
I attach my java code as a text file. It is just a slight modification of the code in the
tutorial.
 
* this is not the real domain.. if anyone wants to know the real domain, please send me a
private e-mail


      
Mime
View raw message