So I have a strong collection variable x (of type NSMutableArray e.g.), when doing dealloc, if I only do x = nil, would it be the same effect as the following?
[x removeAllObjects];
[x release]; // not needed in ARC
x = nil;
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.
Strictly speaking, the two are not identical. Setting a
strongvariable tonilwill indeed release the object. However, an array will onlyremoveAllObjectsif it is getting destroyed. If another variable holds a strong reference to the array, it will stay alive and not remove the items it contains.