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)