dealloc

http://clang.llvm.org/docs/AutomaticReferenceCounting.html#dealloc
http://blog.sunnyxx.com/2014/04/02/objc_dig_arc_dealloc/

- (void)dealloc;

調(diào)用時(shí)機(jī)

A class may provide a method definition for an instance method named dealloc. This method will be called after the final release of the object but before it is deallocated or any of its instance variables are destroyed. The superclass’s implementation of dealloc will be called automatically when the method returns.

大概意思是:dealloc方法在最后一次release后被調(diào)用,但此時(shí)實(shí)例變量(Ivars)并未釋放,父類的dealloc的方法將在子類dealloc方法返回后自動調(diào)用


Subsequent messages to the receiver may generate an error indicating that a message was sent to a deallocated object (provided the deallocated memory hasn’t been reused yet).
You override this method to dispose of resources other than the object’s instance variables, for example:
重寫這個(gè)方法可以處理除了對象的實(shí)例變量之外的其他資源

- (void)dealloc {
    free(myBigBlockOfMemory);
 }

In an implementation of dealloc, do not invoke the superclass’s implementation. You should try to avoid managing the lifetime of limited resources such as file descriptors using dealloc
You never send a dealloc message directly. Instead, an object’s dealloc
method is invoked by the runtime. See [Advanced Memory Management Programming Guide for more details.
arc環(huán)境下不要在dealloc方法中調(diào)用父類的dealloc實(shí)現(xiàn),不要手動調(diào)用dealloc方法


Special Considerations
When not using ARC, your implementation of dealloc must invoke the superclass’s implementation as its last instruction.
mac環(huán)境下,重寫dealloc方法,要在子類實(shí)現(xiàn)的最后一行調(diào)用父類delloc實(shí)現(xiàn)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 來源:http://blog.sunnyxx.com/2014/04/02/objc_dig_arc_deallo...
    看之學(xué)之閱讀 937評論 0 5
  • 轉(zhuǎn)至元數(shù)據(jù)結(jié)尾創(chuàng)建: 董瀟偉,最新修改于: 十二月 23, 2016 轉(zhuǎn)至元數(shù)據(jù)起始第一章:isa和Class一....
    40c0490e5268閱讀 2,030評論 0 9
  • 而我在南方,安然若扇。 時(shí)光真是很奇怪,我依然記得在那個(gè)星期六晚上,專門等到手機(jī)還剩百分之一的電量時(shí)給你發(fā)我喜歡你...
    南離北歸閱讀 303評論 0 0
  • 尋花聞梅嫌春晚 1.尋花問柳,趁春光 周末閑暇別賴床,芳心萌動不須藏。 神雷啟蜇蛹化蝶,尋花問柳趁春光。 3月4日...
    步鹿狐閱讀 411評論 0 1
  • 最近瀏覽騰訊大粵論壇一篇新帖子,闡述一個(gè)來自潮汕16歲的女孩,初中畢業(yè)就出來工作,因?qū)W歷不高、技能欠缺,沒什么人...
    梨家四小姐閱讀 286評論 1 0

友情鏈接更多精彩內(nèi)容