问题描述:

I have a doubt that how we will release the instance variables properly.I know we can do the release in the dealloc method. If we are given as self.instancevariouble=nil in the viewdidunload also will release the object. My question is If there is any problem if we are given the object as nil in the unload method and then also release it in the dealloc method. Also how do I need to release a tableview which is added as IBoutlet in the xib.Can anybody point me in the right direction?

网友答案:

There is no problem with calling release on a nil object but, as a better strategy, move to ARC and most of these concerns will just go away. (Also note that iOS 6 does not unload views.)

网友答案:

If you try to release a nil object it will "work". You can send a message to a nil object without the app crash ;) so you can do this :

UILabel *lbl = nil;
[lbl release];

It won't do anything.

And about "How i need to release a tableview which is added as IBoutlet in the xib.Can anybody point me in the right direction?" You have to "connect" your UITableView in the xib file with your code and do a :

[myTableView release];
网友答案:

If you use self.instanceVariable = nil in the viewDidUnload method (which by the way does no longer get called in iOS 6) the value is of course nil. So if you then release that in the dealloc method you basically call [nil release]; and that does nothing.

相关阅读:
Top