Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

OutOfMemory error

 
Bartender
Posts: 2265
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a code snippet, which sends some request to server and the server returns some response. If the returned response string is too large it's leading to out of memory error. No issues with that, the basic problem is I am not being able to handle that error. Following is the code snippet.


Following is the log stack trace
09-09 14:50:52.100: ERROR/dalvikvm-heap(2419): Out of memory on a 56254246-byte allocation.
09-09 14:50:52.100: INFO/dalvikvm(2419): "AsyncTask #2" prio=5 tid=21 RUNNABLE
09-09 14:50:52.100: INFO/dalvikvm(2419): | group="main" sCount=0 dsCount=0 s=N obj=0x43bec790 self=0x34e610
09-09 14:50:52.100: INFO/dalvikvm(2419): | sysTid=2444 nice=10 sched=0/0 cgrp=bg_non_interactive handle=3467776
09-09 14:50:52.100: INFO/dalvikvm(2419): at org.apache.http.util.CharArrayBuffer.<init>(CharArrayBuffer.java:~55)
09-09 14:50:52.100: INFO/dalvikvm(2419): at org.apache.http.util.EntityUtils.toString(EntityUtils.java:131)
09-09 14:50:52.100: INFO/dalvikvm(2419): at org.apache.http.util.EntityUtils.toString(EntityUtils.java:146)
09-09 14:50:52.110: INFO/dalvikvm(2419): at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:76)
09-09 14:50:52.110: INFO/dalvikvm(2419): at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:59)
09-09 14:50:52.110: INFO/dalvikvm(2419): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657)
09-09 14:50:52.110: INFO/dalvikvm(2419): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627)
09-09 14:50:52.110: INFO/dalvikvm(2419): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:616)
09-09 14:50:52.110: INFO/dalvikvm(2419): at com.a.myproj.util.http.HttpUtils.getHttpGetResponse(HttpUtils.java:24)
09-09 14:50:52.110: INFO/dalvikvm(2419): at com.a.myproj.ui.event.LossDownloadHandler.doInBackground(LossDownloadHandler.java:103)
09-09 14:50:52.110: INFO/dalvikvm(2419): at com.a.myproj.ui.event.LossDownloadHandler.doInBackground(LossDownloadHandler.java:1)
09-09 14:50:52.110: INFO/dalvikvm(2419): at android.os.AsyncTask$2.call(AsyncTask.java:185)
09-09 14:50:52.110: INFO/dalvikvm(2419): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
09-09 14:50:52.110: INFO/dalvikvm(2419): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
09-09 14:50:52.110: INFO/dalvikvm(2419): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
09-09 14:50:52.208: INFO/dalvikvm(2419): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
09-09 14:50:52.218: INFO/dalvikvm(2419): at java.lang.Thread.run(Thread.java:1096)
 
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to handle it write catch block as

 
Swastik Dey
Bartender
Posts: 2265
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. But as per my knowledge Throwable should handle every kind of errors and exceptions. Correct me if I am wrong.
 
Pramod P Deore
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Swastik yes you are correct. Throwable handle every kind of errors and exceptions.
 
Ranch Hand
Posts: 196
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw e;

}



]

Why are you throwing the Exception here in the "CATCH- Block " again... That will definitely cause the program to exit. Stop throwing it .
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic