Jul 09
What would happen with the following code?
MyObject* myObj = [[MyObject alloc] init];
[myObj release];
[myObj method];
Hopefully, if you are lucky, your program will crash. But, it may not, nothing might happen. It may not crash immediately, but only have some other application writes to that memory location.
Therefore, it is typically considered good practice to set myObj to “nil”. This is because, calling a message on “nil” does nothing.
Also, this is safe to do in the scope of your application. Setting an object reference to nil only affects your local scope (essentially zeroing out the pointer), so if that object was retained elsewhere, calling nil will not affect it.