I am debugging a Android slideshow playing app in eclipse. I am trying to generate heap dump in order to find the origin of memory leak but no hprof file is generated in the folder"/data/data/app folder/"android device I am testing. The following is my code for generating the files. What's wrong with that? Thanks in advance!
public class HeapDumpingUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
private static final String HPROF_DUMP_BASENAME = "leak-app-";
private final String dataDir;
public HeapDumpingUncaughtExceptionHandler(String dataDir) {
this.dataDir = dataDir;
Date d = new Date();
CharSequence s = DateFormat.format("yyyy-MM-dd_HH-mm-ss", d.getTime());
String absPath = new File(dataDir, HPROF_DUMP_BASENAME +s+".hprof").getAbsolutePath();
try {
Log.d(this.getClass().toString(),"memory leak app handler: initial heap dump created "+ absPath);
Debug.dumpHprofData(absPath);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Date d = new Date();
CharSequence s = DateFormat.format("yyyy-MM-dd_HH-mm-ss", d.getTime());
String absPath = new File(dataDir, HPROF_DUMP_BASENAME+s+".hprof").getAbsolutePath();
Log.d(this.getClass().toString(),"memory leak app handler: exception caught : "+ex.getClass()+ " heap dump path "+absPath);
try {
Debug.dumpHprofData(absPath);
} catch (IOException e) {
e.printStackTrace();
}
ex.printStackTrace();
}
}
Finally find out I dun reli need this code to generate hprof as DDMS already has this function. Sorry for disturbing you guys and thank you.