ARC 下出现 msg sent to deallocated instance? - V2EX
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
georgetso
V2EX    iDev

ARC 下出现 msg sent to deallocated instance?

  •  
  •   georgetso 2015-05-05 10:50:20 +08:00 3174 次点击
    这是一个创建于 3864 天前的主题,其中的信息可能已经有所发展或是发生改变。
    http://pan.baidu.com/s/1c0jMBny

    打开 zombie check 可以看到崩溃原因是
    2015-05-05 10:41:37.672 test[1710:65851] *** -[GTCollectionViewTableManager respondsToSelector:]: message sent to deallocated instance 0x7c142e10

    项目开启了 ARC,为什么会出现 sent to deallocated instance,如何解决这个问题(请不要使用 cv.datasource = self)?
    13 条回复    2015-05-05 16:02:07 +08:00
    blank_dlh
        1
    blank_dlh  
       2015-05-05 10:59:55 +08:00
    出现 sent to deallocated instance 和 ARC 没什么关系。
    是不是有 assign 的弱引用没有手动置空?
    railgun
        2
    railgun  
       2015-05-05 11:29:25 +08:00
    用 Instruments 开 zombie 查一下。
    多半是1楼说的原因,delegate 销毁掉了,但是CollectionView还没有释放
    georgetso
        3
    georgetso  
    OP
       2015-05-05 11:34:23 +08:00
    @blank_dlh 只有 collectionView.dataSource = manager; collectionView.delegate = manager; 两句。
    dataSource 和 delegate 都是 assign,所以才会出现崩溃。
    问题在于,应该怎么解决这个问题?非得让 dataSource 和 delegate 指向 viewController 吗?
    bzmario
        4
    bzmario  
       2015-05-05 14:58:45 +08:00
    弱引用使用 weak
    georgetso
        5
    georgetso  
    OP
       2015-05-05 15:26:59 +08:00
    @bzmario 这个怎么使用weak?
    datasource和delegate都是SDK定义的属性
    blank_dlh
        6
    blank_dlh  
       2015-05-05 15:28:47 +08:00
    @georgetso GTCollectionViewTableManager dealloc 的时候,把 dataSource 合 delegate 设为 nil 。
    georgetso
        7
    georgetso  
    OP
       2015-05-05 15:30:00 +08:00
    @blank_dlh 不要在意这些细节。我的主要问题是,为什么 manager 被释放了
    black
        8
    black  
       2015-05-05 15:42:35 +08:00   1
    你的manager是局部变量,没有对象持有它,当然被释放了。
    black
        9
    black  
       2015-05-05 15:43:36 +08:00
    把manager声明成ViewController的property,就可以了。
    @property (nonatomic, strong) GTCollectionViewTableManager *manager;
    georgetso
        10
    georgetso  
    OP
       2015-05-05 15:44:12 +08:00
    @black 嗯,这个解释靠谱。赞你一个
    blank_dlh
        11
    blank_dlh  
       2015-05-05 15:46:28 +08:00
    @georgetso 你的 GTCollectionViewTableManager 是个局部变量,出了 viewDidLoad 就没了。。
    georgetso
        12
    georgetso  
    OP
       2015-05-05 15:47:12 +08:00
    @blank_dlh 捂脸奔过,请不要继续戳我的伤口。。。
    blank_dlh
        13
    blank_dlh  
       2015-05-05 16:02:07 +08:00
    @georgetso 哈哈 之前没看到有贴了代码地址
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1142 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 26ms UTC 23:33 PVG 07:33 LAX 15:33 JFK 18:33
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86