美文网首页ios面试题iOS多线程程序员
Dealloc 方法会在哪个线程被执行

Dealloc 方法会在哪个线程被执行

作者: 评评分分 | 来源:发表于2015-09-16 08:40 被阅读676次

如果是一道选择题,那么有可能的选择是:


A. 所有对象的dealloc方法会在主线程调用 

B. 一个对象的dealloc方法会在分配该对象的线程被调用 

C. 一个对象的dealloc方法会在该对象的引用计数变为0的线程被调用


说出你的答案!!!


一小段代码便可以试出答案(thx to@CarinaT):

@Matt Galloway的《Effective Objective-C 2.0》中(page164)对这个问题有描述:

Also, the dealloc method is called on the thread in which the final release that caused the retain count to zero occurred.

相关文章

网友评论

    本文标题:Dealloc 方法会在哪个线程被执行

    本文链接:https://www.haomeiwen.com/subject/hvivcttx.html