Tuesday, July 30, 2013

[android-developers] Re: HttpClient GC_Concurrent freed

Thanks for reply.
I have tryed to look at threads and Heap but i could not find what the problem was.
I will try again if i could find anything.

Den måndagen den 29:e juli 2013 kl. 08:22:12 UTC+2 skrev Kristoffer:
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() {
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) {

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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
For more options, visit this group at
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 android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment