Is It Necessary to Set Pointers to nil in Objective-C After release?

前端 未结 3 1405
后悔当初
后悔当初 2020-12-09 09:40

Is there anything wrong with doing something like

NSString * string = [ [ NSString alloc ] init ];
...
[

3条回答
  •  鱼传尺愫
    2020-12-09 10:11

    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.

提交回复
热议问题