If I have a UIPopoverController (in .h file) and alloc init it multiple times in the same .m file. do I need to release it once to multiple times?
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.
Reference count is at stake here.
Here’s the rule: objects die when no one owns them anymore. If you lose the reference to it without releasing it, you leak.
There are two common ways to gain ownership over an object:
allocmethod)retainon itAnd, as well, there are two common ways to relinquish ownership over an object:
releaseon itautoreleaseon itSo each time you allocate an object, you are responsible for releasing it once you’re done with it. This probably means you only have to release it once, even though you can create it through several code paths. However, you must ensure you release it if you’re going to overwrite the variable with a new object.