Example
-(void)dealloc {
self.myOutletProperty = nil;
[super dealloc];
}
I guess that a sort-of virtual setter will be called. But what exactly happens here? Why nil?
Example
-(void)dealloc {
self.myOutletProperty = nil;
[super dealloc];
}
I guess that a sort-of virtual setter will be called. But what exactly happens here? Why nil?
Nil is the same as null, but for objects. It means no object.
Dot syntax is same as calling [self setMyOutletProperty:nil].
So you just remove an object from some property. Meaning depends on what property you are talking about.
1.If property type is "copy" or "retain", then
self.myOutletProperty = nil; is the same as [myOutletProperty release];
2.If property type is "assign", then
self.myOutletProperty = nil; do nothing
You should know, that property is just syntax sugar.
for example:
@property(nonatomic, retain) NSString *myString;
will convert to
- (NSString*)myString {
return myString;
}
- (void)setMyString:(NSString*)newString {
if (myString != newString) {
[myString release];
myString = [newString retain];
}
}
so if you declare @property in than way, it actually releasing
One thing to keep in mind is that even though setting your property to nil will work fine, I recommend calling [object release]
in your dealloc method instead. This way you're safe if you write our own setter method that references another ivar (which may have already been released) or you have KVO notifications registered on that property somewhere else.