@interface Foo : NSObject
@property (nonatomic, retain) Bar * bar;
@end
@implementation Foo
@synthesize bar = _bar;
- init {
self = [super init];
if (self) {
_bar = [[Bar alloc] init];
// Or
_bar = [[[Bar alloc] init] autorelease];
}
return self;
}
- (void)dealloc {
[_bar release];
[super dealloc];
}
@end
当我运行分析仪时,两者
_bar = [[Bar alloc] init];
和
_bar = [[[Bar alloc] init] autorelease];
没事。
我应该使用哪一个?