jQuery in Action, 3rd edition
The moose likes Android and the fly likes OutOfMemory error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "OutOfMemory error" Watch "OutOfMemory error" New topic

OutOfMemory error

Swastik Dey

Joined: Jan 08, 2009
Posts: 1527

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)

Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 632

to handle it write catch block as

Life is easy because we write the source code.....
Swastik Dey

Joined: Jan 08, 2009
Posts: 1527

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

Joined: Jul 15, 2008
Posts: 632

Hi Swastik yes you are correct. Throwable handle every kind of errors and exceptions.
karthick chinnathambi
Ranch Hand

Joined: Jul 06, 2009
Posts: 196

catch (Throwable e) {
// TODO Auto-generated catch block
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 .

(Born to Win)
I agree. Here's the link: http://aspose.com/file-tools
subject: OutOfMemory error
It's not a secret anymore!