我有一个Android服务,可以运行1-2个小时。 目前这个应用程序正处于调试阶段。服务正在运行时,我随机收到此错误:
F/art ( 2816): art/runtime/indirect_reference_table.cc:86] Check failed: slot_mem_map_.get() != nullptr Failed anonymous mmap(0x0, 12288, 0x3, 0x2, 32, 0): Operation not permitted
...
+ hundreds of lines that belongs to this message regarding the same `indirect_reference_table.cc`.
所以对我来说,好像我的内存已经不见了。我唯一能想到的就是将logcat写入SD卡上的文件。这是我在服务的onStartCommand中开始并在onDestroy中销毁的过程。如下所示:
private Process process;
public int onStartCommand(Intent intent, int flags, int startId) {
...
File appDirectory = new File( Environment.getExternalStorageDirectory() + "/Log" );
File logFile = new File( appDirectory, "logcat.txt" );
if (!appDirectory.exists() && !appDirectory.mkdir())
Log.e("Tag", "Not possible to write file");
try {
process = Runtime.getRuntime().exec("logcat -f " + logFile);
} catch (IOException e) {
e.printStackTrace();
}
return Service.START_STICKY;
}
@Override
public void onDestroy() {
...
process.destroy();
super.onDestroy();
}
任何人都可以说这个错误取决于内存耗尽,主要是因为logcat?和/或有一个解决方案来解决这个崩溃导致我的服务崩溃?