What is the difference between two snippets?
[myObj release];
and
[myObj release];
myObj = nil;
What is the difference between two snippets?
[myObj release];
and
[myObj release];
myObj = nil;
Not much. The second form just prevents you from accidentally trying to reuse the memory as if it was still an object. (As if it was the same object, to be precise. The memory address is likely to be reused for a new object shortly thereafter.)
You have to be careful with the first one, because after you release, the pointer still points to some garbaged memory and can contains some other object. So, in the first one, if you try [myObj release] then [myObj doSomething], the application can crash
My advice is that you should always set it to nil after you release.
when calling release on object the reference-count is decremented. when calling retain the reference-count is incremented.
So as the guys mentioned the pointer will still point to the same place.
If you just release an object, then it will become freed object.
And if you try to perform any sort of operation on freed object then your app crashes. To avoid such accidents, it is always preferred "assign your object to nil after releasing it". Because we all know any operations performed on nil will not be executed :)