dealloc

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

- (void)dealloc;

调用时机

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后被调用,但此时实例变量(Ivars)并未释放,父类的dealloc的方法将在子类dealloc方法返回后自动调用


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:
重写这个方法可以处理除了对象的实例变量之外的其他资源

- (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环境下不要在dealloc方法中调用父类的dealloc实现,不要手动调用dealloc方法


Special Considerations
When not using ARC, your implementation of dealloc must invoke the superclass’s implementation as its last instruction.
mac环境下,重写dealloc方法,要在子类实现的最后一行调用父类delloc实现

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 来源:http://blog.sunnyxx.com/2014/04/02/objc_dig_arc_deallo...
    看之学之阅读 889评论 0 5
  • 转至元数据结尾创建: 董潇伟,最新修改于: 十二月 23, 2016 转至元数据起始第一章:isa和Class一....
    40c0490e5268阅读 1,858评论 0 9
  • 而我在南方,安然若扇。 时光真是很奇怪,我依然记得在那个星期六晚上,专门等到手机还剩百分之一的电量时给你发我喜欢你...
    南离北归阅读 267评论 0 0
  • 寻花闻梅嫌春晚 1.寻花问柳,趁春光 周末闲暇别赖床,芳心萌动不须藏。 神雷启蜇蛹化蝶,寻花问柳趁春光。 3月4日...
    步鹿狐阅读 381评论 0 1
  • 最近浏览腾讯大粤论坛一篇新帖子,阐述一个来自潮汕16岁的女孩,初中毕业就出来工作,因学历不高、技能欠缺,没什么人...
    梨家四小姐阅读 275评论 1 0