To extend the response to CommonsWare:
I have no idea if this works, but you can try adding a top-level exception handler , and there it asks for a bunch of dumps if it's OutOfMemoryError .
I successfully executed his offer in my Android app with the following code:
public class MyActivity extends Activity { public static class MyUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler { @Override public void uncaughtException(Thread thread, Throwable ex) { Log.e("UncaughtException", "Got an uncaught exception: "+ex.toString()); if(ex.getClass().equals(OutOfMemoryError.class)) { try { android.os.Debug.dumpHprofData("/sdcard/dump.hprof"); } catch (IOException e) { e.printStackTrace(); } } ex.printStackTrace(); } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Thread.currentThread().setUncaughtExceptionHandler(new MyUncaughtExceptionHandler()); } }
After creating the dump, you need to copy it from the phone to the computer: Click "Turn on USB storage" on the phone, find the file and copy it to your hard drive.
Then, if you want to use the Eclipse memory analyzer (MAT) to analyze the file, you will need to hide the file: hprof-conv.exe dump.hprof dump-conv.hprof (hprof-conv is under android-sdk/tools )
Finally open dump-conv.hprof with MAT
jfritz42 Aug 03 '11 at 20:22 2011-08-03 20:22
source share