What happens when you call -retain on an object many times? Is it OK to just release it once at when you’re done using it?
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.
consider the name “reference counting“.
you must match each
retainwith arelease(orautorelease).when reference counting, your program may hold one or more references to an object. you add a reference by retaining the object. when you are done with the object, you forfeit the reference using
releaseorautorelease. when all references are returned, the retain count reaches zero and the object is destroyed.object lifetimes are also affected by autorelease pools; a convenience mechanism which reduces the number of manual retains/releases as well as reference counting complexity (in some cases). you should read up on autorelease and autorelease pools for a further understanding of this mechanism.