As Andrey noted, there are cases when assigning nil not only eliminates errors, but is also necessary. Just review typical UIViewController code
- (void)viewDidLoad { button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
In case the controller is loaded, later unloaded (because another view controller is displayed, the memory is low) and finally destroyed, the [button release] in dealloc will re-issue the button (send a message to the released object). Therefore, you must assign nil. A safe solution would be:
- (void)viewDidUnload { // view has been removed [button release]; button = nil; } - (void)dealloc { // destroying the view controller [button release]; // <-- safe }
In these cases, the macro is good and useful. To be more explicit in what he is doing, better call him RELEASE_AND_NIL
#define RELEASE_AND_NIL(X) [X release]; X = nil;
Sebastian
source share