I have the following code, expecting that once obj2 is released obj1 is still retained, will it work?
obj1 = [[Class1 alloc] init];
obj2 = [[obj1 retain] autorelease];
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.
obj1andobj2are both pointers to the same object. That object gets a retain count of 1 when you create it. The object’s retain count increases to 2 when you retain it again on the second line. The object (and any pointers to it) will therefore remain valid until it’s released twice. One of those releases will eventually come from theautoreleaseon the second line; another should be supplied by your code somewhere.