I’ve people who use [variable release] and some other times variable = nil to clean up memory?
When do you use each one? and what are the differences?
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.
If a property is set to
retain, then these 3 are equivalent:[self setProperty:nil];self.property = nil;[property release]; property = nil;In each case, the object will be released, and then set to nil so that all access to the object from then on will not be allowed. “nilling” the instance variable is handy since it ensures you can only ever release the object once in this context because calling
self.property = niltwice will do nothing the second time, but calling[property release]will release the object twice even though you likely only retain it once.Most of the time I find it least bug prone to let retain properties do their thing and try to stay away from explicit
retainandreleasecalls most of the time.