如果出现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. 【UML】

    静态:类图,包图,部署图,构件图,对象图 行为:用例图,活动图,顺序图,状态图,交互图 [类图] http://www.uml.org.cn/oobject/201104212.asp [对象图] h ...

  2. iOS 去掉导航栏最下面线的方法

    导航栏透明,但是字体就不显示了,所以不可行. 下面两种方法是让导航栏下面的线不显示. // 方法1: [[self.navigationController.navigationBar.subview ...

  3. 104)PHP,目录树状输出

    使用特定数量的缩进达到树状目的! 核心问题,计算需要缩进的数量! 缩进级别,与递归调用深度保持一致.每当执行一级递归操作,所找到的文件的缩进级别+; 语法实现: 增加一个参数,表示当前函数调用的深度级 ...

  4. python语法基础-函数-递归函数-长期维护

    ###############    递归   ############## # 递归的定义——在一个函数里再调用这个函数本身 # 递归的最大深度——998 # 二分查找算法 # 你观察这个列表,这是 ...

  5. 源码中TODO、FIXME和XXX的含义

    前言: 今天在阅读Qt  Creator的源代码时,发现一些注释中有FIXME英文单词,用英文词典居然查不到其意义! 实际上,在阅读一些开源代码时,我们常会碰到诸如:TODO.FIXME和XXX的单词 ...

  6. Range Sum Query - Immutable(easy)

    1.这道题目与pat中的1046. Shortest Distance (20)相类似: 2.使用一个数组dp[i],记录0到第i个数的和 3.求i到j之间的和时,输出dp[j]-dp[i]+num[ ...

  7. python初认函数

    今日所得 函数基本使用 函数的参数 函数的返回值 # 函数内要想返回给调用者值 必须用关键字return """ 不写return 只写return 写return No ...

  8. 深入JVM内核--常用JVM配置参数

    Trace跟踪参数 -verbose:gc -XX:+printGC 可以打印GC的简要信息 [GC 4790K->374K(15872K), 0.0001606 secs] [GC 4790K ...

  9. [LC] 136. Single Number

    Given a non-empty array of integers, every element appears twice except for one. Find that single on ...

  10. Java开发面试常见问题合集

    次面试事故 面试官:你看过哪些源码?我:都挺熟悉的面试官:对hashMap了解程度怎么样?面试官:那你能讲讲 HashMap的实现原理吗?面试官:HashMap什么时候会进行 rehash?面试官:结 ...