Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8781517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:19:25+00:00 2026-06-13T20:19:25+00:00

Getting Out of memory error while loading large string from the server. This is

  • 0

Getting Out of memory error while loading large string from the server.

This is my code:

public String sendRequest(HttpRequest httpRequest){
        Log.d(TAG, "Sending HTTP request to the server");
        Log.d("memory", "memory size is:"+Runtime.getRuntime().maxMemory());
        String response = null;
        HttpHost host = new HttpHost(context.getString(R.string.HOST), -1, context.getString(R.string.SCHEME));
        try {
            HttpResponse httpResponse = httpClient.execute(host, httpRequest);
            int status=httpResponse.getStatusLine().getStatusCode();

            if (status==200) {
                HttpEntity responseEntity = httpResponse.getEntity();
                if (responseEntity != null) {   
                    InputStream stream = responseEntity.getContent();
                    response = convertStreamToString(stream);
                    stream.close();                     
                }
            }
            else{
                response="failed:"+httpResponse.getStatusLine().toString();
            }
        } catch (Exception e) {
            Log.v(TAG,"Request sending failed: ", e);
        }
        Log.d(TAG, "Completed, Sending HTTP request to the server");
        return response;
    }   
    /**
     * Convert stream to string.
     *
     * @param is the input Stream.
     * @return the string
     */
    private String convertStreamToString(InputStream is) {  
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        StringBuilder sb = new StringBuilder();

        String line = null;
        try {
            while ((line = reader.readLine()) != null) {
                sb.append(line + NEW_LINE);
            }
            reader.close();

        } catch (IOException e) {
            //do nothing.
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                //do nothing.    
            }
        }
        reader=null;
        return sb.toString();
    }

I am getting exception at this line:

while ((line = reader.readLine()) != null) {
    sb.append(line + NEW_LINE);
}

This is my logcat details:

10-10 15:01:50.270: D/dalvikvm(632): GC_FOR_ALLOC freed <1K, 37% free 24085K/38215K, paused 225ms
10-10 15:01:51.032: I/dalvikvm-heap(632): Grow heap (frag case) to 31.845MB for 8628650-byte allocation
10-10 15:01:51.929: D/dalvikvm(632): GC_CONCURRENT freed <1K, 15% free 32511K/38215K, paused 10ms+32ms
10-10 15:01:52.192: D/dalvikvm(632): GC_FOR_ALLOC freed 0K, 15% free 32511K/38215K, paused 226ms
10-10 15:01:52.192: I/dalvikvm-heap(632): Forcing collection of SoftReferences for 12942970-byte allocation
10-10 15:01:52.589: D/dalvikvm(632): GC_BEFORE_OOM freed 9K, 15% free 32502K/38215K, paused 299ms
10-10 15:01:52.589: E/dalvikvm-heap(632): Out of memory on a 12942970-byte allocation.
10-10 15:01:52.589: D/dalvikvm(632): GC_BEFORE_OOM freed 9K, 15% free 32502K/38215K, paused 299ms
10-10 15:01:52.589: E/dalvikvm-heap(632): Out of memory on a 12942970-byte allocation.
10-10 15:01:53.219: E/AndroidRuntime(632): FATAL EXCEPTION: IntentService[SurveyQuestionService]
10-10 15:01:53.219: E/AndroidRuntime(632): java.lang.OutOfMemoryError
10-10 15:01:53.219: E/AndroidRuntime(632):  at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:94)
10-10 15:01:53.219: E/AndroidRuntime(632):  at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:145)
10-10 15:01:53.219: E/AndroidRuntime(632):  at java.lang.StringBuilder.append(StringBuilder.java:216)
10-10 15:01:53.219: E/AndroidRuntime(632):  at com.handigital.products.agilesurveys.services.SurveyQuestionService.processResponse(SurveyQuestionService.java:34)
10-10 15:01:53.219: E/AndroidRuntime(632):  at com.handigital.products.agilesurveys.services.AbstractIntentService.onHandleIntent(AbstractIntentService.java:44)
10-10 15:01:53.219: E/AndroidRuntime(632):  at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
10-10 15:01:53.219: E/AndroidRuntime(632):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-10 15:01:53.219: E/AndroidRuntime(632):  at android.os.Looper.loop(Looper.java:137)
10-10 15:01:53.219: E/AndroidRuntime(632):  at android.os.HandlerThread.run(HandlerThread.java:60)

Any one can please help me on this.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:19:26+00:00Added an answer on June 13, 2026 at 8:19 pm

    One way to solve this problem. In animation you can call Runtime.getRuntime().gc();
    to invoke garbage collector. also in activity onDestroy() method u can call Runtime.getRuntime().gc();

    You can even refer the link below,

    How to resolve out of memory issue

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this out of memory error: java.lang.RuntimeException: java.lang.OutOfMemoryError: <classname>: Unable to expand
I am getting a segmentation fault while running this code. I can't work out
I'm getting this error while doing a git svn rebase in cygwin Out of
So while running this code I keep getting the error: /Applications/TextMate.app/Contents/SharedSupport/Bundles/C.tmbundle/Support/bin/bootstrap.sh: line 7: 11441
I keep getting a out of memory error in LuaJit. How do I increase
First of all I am getting memory leak while scrolling tableview out of bounds.
I am getting time out from using JsonpRequestBuilder. The entry point code goes like
What are the most common reasons that I would be getting this error from
I am getting a out of memory error when calling a method user BufferedReader
This seems to be in infamous error . I remember getting it a while

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.