If you set a property to nil in viewDidUnload do you need to release it again in dealloc?
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.
No, but:
[nil release]is fine.viewDidUnloadbeing called.So just release as normal in
-dealloc.Of course, you must make sure that you actually released the previous object. You implicitly do this if you used the synthesized setter:
But setting the ivar to nil will leak:
These are common errors.
Also note that setting properties to nil in
-deallocis a bad idea. As Kendall points out in the comments, you may unexpectedly invoke KVO behavior. There’s a fuller discussion at Properties in dealloc: release then set to nil? or simply release.