我正在调试在eclipse中播放应用的Android幻灯片。我正在尝试生成堆转储,以便找到内存泄漏的原因,但是我正在测试的文件夹“/ data / data / app folder /”中没有生成hprof文件。以下是我生成文件的代码。这有什么问题?提前谢谢!
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();
}
}
答案 0 :(得分:0)
最后发现我dli reli需要这个代码来生成hprof,因为DDMS已经具有此功能。很抱歉打扰你们,谢谢你们。