3

In my app I refresh data every 3 minutes. If app will work for couple hours I'go this kinda error:

java.lang.OutOfMemoryError
at org.apache.http.util.CharArrayBuffer.<init>(CharArrayBuffer.java:55)
at org.apache.http.util.EntityUtils.toString(EntityUtils.java:131)
at org.apache.http.util.EntityUtils.toString(EntityUtils.java:146)
at com.tab.Api.friends(Api.java:99)
at com.tab.TabLayout.updateFriends(TabLayout.java:692)
at com.tab.TabLayout.access$25(TabLayout.java:690)
at com.tab.TabLayout$7.run(TabLayout.java:684)
at java.lang.Thread.run(Thread.java:1102)

While my code in this: "at com.tab.Api.friends(Api.java:99)" place looks like this:

    String result = "";
    JSONObject jArray = null;
    JSONArray friends = null;

    DefaultHttpClient client = new DefaultHttpClient();   
    try
    {
        HttpGet getFriends = new HttpGet("http://##########"+fb);
        HttpResponse getResponseFriends = client.execute(getFriends);
        HttpEntity getFriendsEntity = getResponseFriends.getEntity();                      
        if (getFriendsEntity != null) 
            result= EntityUtils.toString(getFriendsEntity);   
        try
        {
            jArray = new JSONObject(result);
        }
        catch(JSONException e)
        {

        }
    }
    catch(Exception e)
    {   
        Log.d("LOADING ERROR","Friends section");
    }

3 Answers 3

3

You have a memory leak somewhere. Somewhere you hold references to memory intensive data in a long lived object. By this the GC cannot collect those data. Your app will use even more memory the longer it is running until all the memory is used up. Then your app is killed with an OutOfMemory Exception

Links that might help you:

Sign up to request clarification or add additional context in comments.

Comments

0

Try to use MAT tool to analyse memory allocations. It's possible that you have memory leak in UI or some other part. I think that code where this error happens is not the cause of error but only a result. This tutorial could help you: http://macgyverdev.blogspot.com/2011/11/android-track-down-memory-leaks.html

One more thing - better not to catch Exception, but something more specific (like IOException etc). By catching Exception you may catch something not meant to be catched here (f.e. NullPointerException) and will make problems elsewhere in code.

Comments

0

I think, Webservice return large amount of data which is not held by your mobile Ram.

I had same problem when I worked in This type of webservice project.

Please make webservice which provide limited data eg. 10km far from of current location records.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.