What is the difference between these two code snippets:
object = nil;
[object release]
Vs
[object release];
object = nil;
which is the best practice ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Don’t do that. You are sending a
releasemessage on a nil object that will just do nothing. But the object that was referenced by your object is still in memory because it has never received areleasemessage.Here you release the object, and for convenience and security, you set
nilto its reference. So you can call (by mistake of course 🙂 ) any method on that object and the app won’t crash.But if you use a retained property
@property(nonatomic, retain), calling :equals to call :