iOS 内存错误调试(EXC_BAD_ACCESS)

时间:2023-03-09 17:26:58
iOS 内存错误调试(EXC_BAD_ACCESS)

内存错误crash现场:

iOS 内存错误调试(EXC_BAD_ACCESS)

Thread堆栈:

iOS 内存错误调试(EXC_BAD_ACCESS)

有可能是访问被释放对象造成,根据现场并不能找到具体哪个对象出现内存错误。

1.开启僵尸对象调试

Edit Scheme->Debug->Diagnostics->Enable Zombie Objects

2.闪退后查看控制台,看输出应该是某个Button出错

-- ::49.959 funmiosbr_ZQB[:] *** -[UIButton setHidden:]: message sent to deallocated instance 0x185942a0

3.由于新版xcode默认调试器为lldb,旧版本gdb调试器可以使用如下命令查看

(gdb) info malloc-history 0x185942a0

(1)Profile your project

(2)Select Zombies from the list of instruments

(3)Make your app trigger the problem

(4)At this point you should be presented with the address that was already deallocated and you can explore it.

(5)定位问题

iOS 内存错误调试(EXC_BAD_ACCESS)