开发者

Objective-C - Do I need to de-alloc a retained property that isn't used?

开发者 https://www.devze.com 2023-01-27 13:07 出处:网络
If I have a custom vie开发者_Python百科w controller class that I want to reuse but when used in one instance has a retained property that isn\'t actually used during the view\'s lifecycle, do I need t

If I have a custom vie开发者_Python百科w controller class that I want to reuse but when used in one instance has a retained property that isn't actually used during the view's lifecycle, do I need to release it in dealloc?


You should release any objects that you alloc or retain in dealloc.

If it's referenced in interface builder, you'll also want to release and set to nil in the viewDidUnload() of your view controller as well as releasing in your dealloc.


It's OK to send messages to nil, so you should just release your retain properties in dealloc no matter what. If the property hasn't been used, it will be nil and sending release to it is effectively a no-op.


You don't need to call release on a retained property. The setter method is implemented such that giving it a null value will release it for you. In your dealloc method just set it to nil:

self.someProperty = nil;
0

精彩评论

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

关注公众号