开发者

Objective C: Subclassing, overriding dealloc

开发者 https://www.devze.com 2023-02-20 22:25 出处:网络
I am creating a subclass of a custom UITableViewCell.The superclass has some properties that it is releasing in the dealloc method.I have added one additional property in my subclass, so I made sure t

I am creating a subclass of a custom UITableViewCell. The superclass has some properties that it is releasing in the dealloc method. I have added one additional property in my subclass, so I made sure to override the dealloc method and release my new property.

My question is, since I overrode the dealloc method, will the properties that were released in super class 开发者_C百科dealloc method not get released (I AM calling [super dealloc])? Do I need to specifically release those in MY dealloc method?


If you are calling [super dealloc], then the superclass implementation of -dealloc will still be run. The superclass should be responsible for releasing its own properties. So no, you don't need to release the superclass properties. In fact, doing so will likely cause your application to crash.


If you are calling [super dealloc], you are fine. That method won't know if it was called by a subclass or directly by the runtime, and it will do its usual work and take care of its own properties as always.


Important: Call [super dealloc] last in your -dealloc method, after you've your own ivars and done anything else you need to do in -dealloc. There won't be anything left of your object when that method returns.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号