Possible Duplicate:
Why use 'self.' when its not forced?
What is the difference between these 2 blocks of code?
@property (nonatomic, retain) MyObject *myObject;
MyObject *obj = [[MyObject alloc] init];
self.myObject = obj;
[obj release];
MyObject *obj = [[MyObject alloc] init];
myObject = obj;
[obj release];
EDIT:
Does it mean that on the second block I don’t need to release “obj” ?
In the first case,
self.myObjectimplies thatmyObjectis a@property, and when you assign to it withself.myObject = obj, that property’s setter will get invoked. Often, that setter is automagically generated by the compiler with the@synthesizedirective. If that property’s autogenerated setter is flagged withretain, then whatever assigned to it (in this case,obj) will be retained by the property.In the second case,
myObjectmay or may not be a property. Regardless, this is a simple assignment. Noretainis done.