当我在dealloc方法中将一个属性设置为nil时,会发生什么? [英] What happens exactly, when I set an property to nil in the dealloc method?
本文介绍了当我在dealloc方法中将一个属性设置为nil时,会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例
-(void)dealloc {
self.myOutletProperty = nil;
[super dealloc];
}
我猜想会调用一种虚拟setter。但究竟发生了什么?为什么是nil?
I guess that a sort-of virtual setter will be called. But what exactly happens here? Why nil?
推荐答案
你应该知道,该属性只是语法糖。
You should know, that property is just syntax sugar.
例如:
@property(nonatomic, retain) NSString *myString;
将转换为
- (NSString*)myString {
return myString;
}
- (void)setMyString:(NSString*)newString {
if (myString != newString) {
[myString release];
myString = [newString retain];
}
}
所以如果你声明@property,实际上是发布
so if you declare @property in than way, it actually releasing
这篇关于当我在dealloc方法中将一个属性设置为nil时,会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文