Possible Duplicate:
Why setting to nil after releasing?
Which of the following examples are correct? I’ve seen different programmers / apps doing this in different ways and I just really want to know what’s the right way to releasing an object. Is it required to set the object to nil after releasing it?
Example
API *api_handle = [[API alloc] init];
[api callmethod];
[api release];
api = nil;
Or
API *api_handle = [[API alloc] init];
[api callmethod];
[api release];
In other words, is it necessary to set the object to nil after being released? If not, why do people do it? If so, what are the benefits of doing it?
It’s not required per se but it’s generally good practice if the variable you’re using has a scope that extends past the
-releasemessage.