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

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

Is there anything wrong with doing something like

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

3条回答
  •  离开以前
    2020-12-09 10:04

    Setting an instance variable to nil is more useful in a multi-threaded application than a single-threaded one, since with multiple threads you can't always guarantee that an instance variable will only be read before it's released.

    I generally don't bother in single-threaded applications, unless there's some other compelling reason.

提交回复
热议问题