我对 iOS 开发还比较陌生,所以如果这是一个弱智的问题,请原谅我。我读了this http://useyourloaf.com/blog/2012/08/01/property-synthesis-with-xcode-4-dot-4.html但我还是有点困惑。
我没有使用ARC。 (是的,我知道我应该,但我现在不这样做)在我的类标题中我有这个
/*-----------------------------------------------------------------------+
| The name of the sender/receiver
+-----------------------------------------------------------------------*/
@property (nonatomic, retain) NSString *name;
我不合成这个变量,而是让编译器完成这项工作。
以下哪项被认为是最佳实践dealloc
method
#1释放 iVar
-(void) dealloc {
[_name release];
[super dealloc];
}
#2解除分配该属性
-(void) dealloc {
[self.name release];
[super dealloc];
}
#3最后一个问题。通常是设置property
to nil
in the dealloc
方法? IE。
-(void) dealloc {
[self.name release];
self.name = nil;
[super dealloc];
}
如果有人能向我解释这一点,我将非常感激。
Regards!
Jeff Lamarche 写了一篇关于在 dealloc 中释放变量的好文章:http://iphonedevelopment.blogspot.nl/2010/09/dealloc.html http://iphonedevelopment.blogspot.nl/2010/09/dealloc.html
他建议永远不要使用self.
语法,因为它可能会在多线程环境中导致问题。
他的建议是使用iVar
并设置为nil
在生产版本中:
-(void) dealloc {
[_name release], _name = nil;
[super dealloc];
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)