发布后是否有必要在Objective-C中将指针设置为nil? [英] Is It Necessary to Set Pointers to nil in Objective-C After release?
本文介绍了发布后是否有必要在Objective-C中将指针设置为nil?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
做类似事情
NSString * string = [ [ NSString alloc ] init ];
...
[ string release ];
NSString * string = [ [ NSString alloc ] init ];
...
[ string release ];
或者添加
string = nil;
?
推荐答案
不是必需的,但是是很好的做法.如果您在发布后无意中引用了它,则可能会发生不好的事情,但是在目标C中,引用nil并没有任何危害.
Not necessary, but good practice. If you were to inadvertently reference it after release, bad things could happen, but in Objective C there isn't any harm in referencing a nil.
这篇关于发布后是否有必要在Objective-C中将指针设置为nil?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文