For example:
MyClass *obj1 = [[MyClass alloc] init];
MyClass *obj2 = [obj1 retain];
and release it with
[obj2 release];
[obj2 release];
Is it legal to do this? Will the object will be released properly?
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.
Yep, it’ll work fine. You’re calling release on the same object, no matter which pointer variable you use to do so.
Looks a bit weird though.
And, a common idiom would be
which clearly wouldn’t work if you used obj2 in both lines.