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?
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?
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
[obj1 release], obj1 = nil;
[obj2 release], obj2 = nil;
which clearly wouldn't work if you used obj2 in both lines.