if i have an outlet variable which i’ve declared as a property
@interface MyClass:UIViewController
{
IBOutlet UILabel *label;
}
@property (nonatomic,retain) IBOutlet UILabel *label;
is there a difference between doing this
[label release];
and this
[self.label release];
Yes there is a difference, when you’re using a property, you’re implicitly using an accessors, that is to say :
So some additional behavior could be implemented in the getter, such as sanity check and so on.
Here you declared your property as retain :
So the setter will automatically retain the value to set, and release the old one.
Using :
You are doing something hazardous, as you release the object which is retained by the accessors. So when you do something like :
It calls the method
- (void) setLabel:(UILabel*)labelwhich will release the actual object! So the object will be released twice, leading to freed object access!If you declare a property, try to only use your member through this property !
You can also use some implicit member declaration, such as :
A member
UILabel* _labelwill be implicitly declared 🙂