ARC 下出现 msg sent to deallocated instance?

2015 年 5 月 5 日
 georgetso
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)?
3321 次点击
所在节点    iDev
13 条回复
blank_dlh
2015 年 5 月 5 日
出现 sent to deallocated instance 和 ARC 没什么关系。
是不是有 assign 的弱引用没有手动置空?
railgun
2015 年 5 月 5 日
用 Instruments 开 zombie 查一下。
多半是1楼说的原因,delegate 销毁掉了,但是CollectionView还没有释放
georgetso
2015 年 5 月 5 日
@blank_dlh 只有 collectionView.dataSource = manager; collectionView.delegate = manager; 两句。
dataSource 和 delegate 都是 assign,所以才会出现崩溃。
问题在于,应该怎么解决这个问题?非得让 dataSource 和 delegate 指向 viewController 吗?
bzmario
2015 年 5 月 5 日
弱引用使用 weak
georgetso
2015 年 5 月 5 日
@bzmario 这个怎么使用weak?
datasource和delegate都是SDK定义的属性
blank_dlh
2015 年 5 月 5 日
@georgetso GTCollectionViewTableManager dealloc 的时候,把 dataSource 合 delegate 设为 nil 。
georgetso
2015 年 5 月 5 日
@blank_dlh 不要在意这些细节。我的主要问题是,为什么 manager 被释放了
black
2015 年 5 月 5 日
你的manager是局部变量,没有对象持有它,当然被释放了。
black
2015 年 5 月 5 日
把manager声明成ViewController的property,就可以了。
@property (nonatomic, strong) GTCollectionViewTableManager *manager;
georgetso
2015 年 5 月 5 日
@black 嗯,这个解释靠谱。赞你一个
blank_dlh
2015 年 5 月 5 日
@georgetso 你的 GTCollectionViewTableManager 是个局部变量,出了 viewDidLoad 就没了。。
georgetso
2015 年 5 月 5 日
@blank_dlh 捂脸奔过,请不要继续戳我的伤口。。。
blank_dlh
2015 年 5 月 5 日
@georgetso 哈哈 之前没看到有贴了代码地址

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://study.congcong.us/t/188544

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX