V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
notedit
V2EX  ›  iDev

大家平常遇到EXC_BAD_ACCESS 是怎样解决的?

  •  
  •   notedit ·
    notedit · 2013-03-26 12:42:06 +08:00 · 3049 次点击
    这是一个创建于 4050 天前的主题,其中的信息可能已经有所发展或是发生改变。
    这两天被这个问题给虐死了 一段程序时好时坏
    15 条回复    1970-01-01 08:00:00 +08:00
    sumanx
        1
    sumanx  
       2013-03-26 12:52:48 +08:00
    开启Zombie Enabled,如果找不到,就一段一段的屏蔽可能相关的dealloc。
    一般是声明一个retain的property,结果赋值的时候没用self.xxx = yyy而是用了xxx = yyy导致的。

    如果没用用arc,看有没有在dealloc里手误导致释放什么变量多释放了一次。。
    alexrezit
        2
    alexrezit  
       2013-03-26 12:56:01 +08:00
    pointer 木有搞清楚吧... =.=
    notedit
        3
    notedit  
    OP
       2013-03-26 12:59:46 +08:00
    @sumanx 使用了arc dealloc里也没有释放 是一些private的变量 然后传给其他的模块 然后就会出现这种情况 而且比较随机
    notedit
        4
    notedit  
    OP
       2013-03-26 13:00:30 +08:00
    @alexrezit 确实没有搞清楚 边看边学也就一个多月
    sumanx
        5
    sumanx  
       2013-03-26 13:27:32 +08:00   ❤️ 1
    @notedit 用了arc,你得用retain的property来保存别的函数要用到的变量,不然如果你在a函数中给它赋值,a一执行结束,那个变量就被释放了,别处一使用就exc_bad_access
    sumanx
        6
    sumanx  
       2013-03-26 13:28:16 +08:00
    前面说的是对象。
    yadizzz
        7
    yadizzz  
       2013-03-26 13:30:11 +08:00
    挂个全局断点,一crash就断到代码行了,无非就是野指针什么的问题
    alexrezit
        8
    alexrezit  
       2013-03-26 13:32:24 +08:00
    @notedit
    如果内存被释放而 pointer 没有设成 nil 就会继续指向那块无效的内存.
    ydhydh
        9
    ydhydh  
       2013-03-26 13:35:00 +08:00
    时好时坏 ,多线程?
    doskoi
        10
    doskoi  
       2013-03-26 13:36:08 +08:00   ❤️ 1
    EXC_BAD_ACCESS 肯定是memory management的问题
    不是zombile就是leak
    instruments一般都能抓到
    notedit
        11
    notedit  
    OP
       2013-03-26 14:31:05 +08:00
    @sumanx 如果我这边变量是private的呢 这种情况该怎么处理 我现在的做法是 在传递给另一个模块的时候把这个变量copy 一下 可以解决我的问题 但不知道是不是好的方法
    notedit
        12
    notedit  
    OP
       2013-03-26 14:51:18 +08:00
    @sumanx 我把这个变量变成public 的然后用remain修饰 解决了
    alexrezit
        13
    alexrezit  
       2013-03-26 16:04:09 +08:00   ❤️ 1
    qdvictory
        14
    qdvictory  
       2013-03-27 12:49:19 +08:00   ❤️ 2
    这种错误大多数情况下都是野指针造成的,不用的指针置nil是一个很好的习惯。
    feihu
        15
    feihu  
       2013-03-27 12:54:05 +08:00
    malloc_history
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   882 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:52 · PVG 05:52 · LAX 14:52 · JFK 17:52
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.