Hello.
Iam having trouble with memory leak it will finaly cause the app to force
close.
I have stripped down my code just to find where the problem is and i
located it to my httpclient.
When i run this code iam geting many GC_Concurrent freed.
if i add a Thread.sleep(1000); then i will ofcourse get less warnings but
my guess is that there is still some problem with the code i run.
Is there a way i could prevent the problem.
Here is the code:
Thread c = new Thread() {
@Override
public void run() {
String xml;
UsernamePasswordCredentials creds = new
UsernamePasswordCredentials("username", "password");
HttpGet httpGet;
HttpClient httpClient;
HttpResponse httpResponse;
HttpEntity httpEntity;
while (RunThread) {
try {
httpClient = HttpClientFactory.getThreadSafeClient();
httpGet = new HttpGet("http://ipaddress/list?format=xml");
httpGet.addHeader(new BasicScheme().authenticate(creds, httpGet));
httpResponse = httpClient.execute(httpGet);
httpEntity = httpResponse.getEntity();
xml = EntityUtils.toString(httpEntity, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
}
};
c.start();
}
And here is the class HttpClientFactory
public class HttpClientFactory {
private static DefaultHttpClient client;
public synchronized static DefaultHttpClient getThreadSafeClient() {
if (client != null)
return client;
client = new DefaultHttpClient();
ClientConnectionManager mgr = client.getConnectionManager();
HttpParams params = client.getParams();
params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
10000);
params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 10000);
client = new DefaultHttpClient(
new ThreadSafeClientConnManager(params,
mgr.getSchemeRegistry()), params);
return client;
}
}
Have a made some huge mistage in the code that is causing this issue?
--
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.