我正在 Eclipse 中调试一个 Android 幻灯片播放应用程序。我正在尝试生成堆转储以查找内存泄漏的来源,但在我正在测试的文件夹“/data/data/app 文件夹/”android 设备中没有生成 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();
}
}