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


Is there anything wrong with doing something like

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

or is there any value (other than best practice) in also adding

string = nil;


Best Solution

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.