如果出现exc_bad_access错误,基本上是由于内存泄漏,错误释放,对一个已经释放的对象进行release操作。但是xcode有时候不会告诉你错误在什么地方(Visual Studio这点做得很好)。不过我们可以通过设置xcode环境变量环境变量NSZombieEnabled,MallocStackLogging查看错误的来源:

1、菜单 Product > Manage Schemes;

2、选中当前的Scheme,点Edit按钮;

3、设置环境变量。在Arguments > Environment Variables;

4、添加环境变量MallocStackLogging,NSAutoreleaseFreedObjectCheckEnabled,MallocStackLoggingNoCompact,NSZombieEnabled并设置YES

5、最后记得把环境变量删除或设置为NO,因为它们会使得内存不会被释放.

message sent to deallocated instance后会有一个内存地址,如:0×6497860,我们需要查看该地址的malloc history.查看方法,在原来的gdb下,使用”info malloc_history 0×6497860“即可显示malloc记录。但是新版的Xcode 不再支持,怎么办呢?秀逗麻袋,我们还有terminal,使用终端的malloc_history命令,如”malloc_history 32009 0×6497860“或者“sudo malloc_history 32009 0×6497860”即可显示。其中的32009是该进程的pid,根据这个malloc记录,可以大致定位出错信息的代码位置。

会出现类似以下提示代码,根据提示就可以找出错误具体位置

ALLOC 0xfcdff50-0xfce00b7 [size=]: thread_3bf2a28 |start | main | UIApplicationMain | GSEventRun
| GSEventRunModal | CFRunLoopRunInMode | CFRunLoopRunSpecific | __CFRunLoopRun | __CFRunLoopDoObservers
| __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ | _afterCACommitHandler | _applyBlockToCFArrayCopiedToStack
| ___afterCACommitHandler_block_invoke | __38-[UITableView touchesEnded:withEvent:]_block_invoke |
 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] | -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] | -[MessageListViewController tableView:didSelectRowAtIndexPath:] | _objc_rootAlloc | class_createInstance | calloc | malloc_zone_calloc

Xcode调试之exc_bad_access以及 message sent to deallocated instance的更多相关文章

  1. iOS内存错误EXC_BAD_ACCESS的解决方法(message sent to deallocated instance)

    iOS开发,最郁闷的莫过于程序毫无征兆地就崩溃了,用bt命令打出调用栈,给出的是一堆系统EXC_BAD_ACCESS的信息,根本没办法定位问题出现在哪里.通常这样的崩溃出现,原因一般就是:调用了已经释 ...

  2. 解决LLDB模式下出现message sent to deallocated instance错误

    本文在源文的基础上做整理:http://www.devdiv.com/home.php?mod=space&uid=50901&do=blog&id=50856 Xcode版本 ...

  3. 如何在LLDB下排查message sent to deallocated instance问题

    转:http://www.devdiv.com/home.php?mod=space&uid=50901&do=blog&id=50856 在XCode的以前版本中,如果遇到了 ...

  4. message sent to deallocated instance

    在XCode的以前版本中,如果遇到了 [代码]c#/cpp/oc代码: 1 message sent to deallocated instance 0x6d564f0 我们可以使用info mall ...

  5. 捉襟见肘之message sent to deallocated instance 0x16f62a70

    出现的问题(真机ios8到ios9测试没有问题,真机ios7.1出现问题): -- :::60b] *** -[ChatViewController scrollViewDidScroll:]: me ...

  6. [UIImage _isCached]: message sent to deallocated instance

    本文转载至 http://zhuhaibobb.blog.163.com/blog/static/2744006720124191633375/       这几天做了个APP打开20份钟左右就强制退 ...

  7. runtime MethodSwizzle 实践之 奇怪crash : [UIKeyboardLayoutStar release]: message sent to deallocated instance

    情景: 使用MethodSwizzle 实现对数组.字典 等系统方法的安全校验.显然能达到预期效果,但实际发现当 键盘显示的情况下  home app 进入后台,再单击app  图标 切换回前台时 发 ...

  8. UICollectionView [NSIndexPath section]: message sent to deallocated instance

    在UICollectionView上加UITapGestureRecognizer手势时,点击哪都报 [NSIndexPath section]: message sent to deallocate ...

  9. [CALayer release]: message sent to deallocated instance iOS内存过度释放问题

    [CALayer release]: message sent to deallocated instance iOS内存过度释放问题 解决方式: 1:先找到过度释放的 内存指针 开启-僵尸模式:xc ...

随机推荐

  1. Spring的分模块开发的配置

    参考:Spring学习笔记-Spring的分模块开发的配置 在加载配置文件的时候,加载多个 例如把applicationContext.xml配置文件中的关于集合配置的部分剪切到application ...

  2. Android7.0 USBCamera设备/dev/video0无读权限

    Android7.0的系统,具备root权限,执行 # adb shell # su # chmod 777 /dev/video0 在5.0的系统中可以预览图像,7.0返回无读权限 File fil ...

  3. [LC] 225. Implement Stack using Queues

    Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...

  4. Rancher的部署安装(编排选用K8S)

    为什么要使用Rancher Rancher是一个开源的企业级容器管理平台.通过Rancher,企业再也不必自己使用一系列的开源软件去从头搭建容器服务平台.Rancher提供了在生产环境中使用的管理Do ...

  5. IPFS问题总结

    1.安装包下载 ipfs安装版本下载:https://github.com/ipfs/go-ipfs/releases,这是IPFS的go语言实现版,目前实现的还有js版本. 2.安装与启动 linu ...

  6. 使用nodeJs安装Vue-cli并用它快速构建Vue项目

    部分摘自:http://www.cnblogs.com/wisewrong/p/6255817.html(已在本地测试) 前提:nodeJs本地已安装. 一.安装 vue-cli 1.使用nodeJs ...

  7. SWUST OJ Euclid's Game(0099)

    Euclid's Game(0099) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 1855 Accepted: 589   De ...

  8. 吴裕雄--天生自然KITTEN编程:移动与旋转

  9. The Monster(Codeforce-C-思维题)

    C. The Monster time limit per test 1 second memory limit per test 256 megabytes   As Will is stuck i ...

  10. windows 下 基于express搭建 https协议的网站

    参考 https://blog.csdn.net/xingyanchao/article/details/79362443 问题在于生成SSL证书的时候Windows环境下会报错 解决方案 参考 ht ...