• Post Reply Bookmark Topic Watch Topic
  • New Topic

OutOfMemory error  RSS feed

 
Rancher
Posts: 1816
15
Android Eclipse IDE Java Java ME
  • 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
Rancher
Posts: 1816
15
Android Eclipse IDE Java Java ME
  • 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 .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!