fuz*_*oat 12 iphone cocoa-touch objective-c
在实现dealloc时,我在书籍和网络上查看各种代码时都注意到了一点混乱.我的问题是在使用@property时我应该使用以下哪个.到目前为止,我一直在使用VERSION_001.
@property(nonatomic, retain) NSString *name;
@property(nonatomic, retain) NSString *type;
@property(nonatomic, retain) NSString *payload;
@property(nonatomic, retain) NSString *orbit;
Run Code Online (Sandbox Code Playgroud)
版本001
- (void)dealloc {
[name release];
[type release];
[payload release];
[orbit release];
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
版本002
- (void)dealloc {
[self setName:nil];
[self setType:nil];
[self setPayload:nil];
[self setOrbit:nil];
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
Ric*_*III 17
没有真正的区别,除非你没有使用@synthesize关键字.当您将属性设置为nil时,它们将由setter在幕后释放.现在,第一版可能会有轻微的性能提升,因为不需要在幕后发生(例如指针比较,以及苹果隐藏在幕后的其他所有内容).我总是使用版本001,因为它更加重要,未来的开发人员不必挖掘我的代码来弄清楚我正在完成的事情.
| 归档时间: |
|
| 查看次数: |
2049 次 |
| 最近记录: |