Will the pointer to an object go to nil when its count goes to 0 or when dealloc is called? Why or why not?
Will the pointer to an object go to nil when its count goes to
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, it won’t, because the deallocation does not have the power to change the pointer. It could only do this is you passed a pointer to the pointer.
If you want to ensure it’s set to nil, you have to do it yourself.
Some consider this good practice, some consider it a waste of time since your code should be structured to not use pointers after deallocation (until reallocated).
I actually lean towards the latter camp but I can see why people want to protect themselves from accessing freed memory (programming defensively is rarely a bad idea).