Are there any rules of thumb when working with Objective-C that would help me understand when is the right time to release variables?
Share
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.
NARC! 🙂
If you invoked a method that contains N ew, A lloc, R etain, or C opy, then you must
releaseorautorelease. Otherwise you don’t touch it.Of course, anything the documentation explicitly says trumps this rule.
The other thing is that when you’re dealing with C function the NARC rule still applies, but also gets the Create rule: if the function contains “create”, then you’re responsible for CFReleasing or freeing the returned data.