在属性的 getter 函数(即自动生成)中
name
,对象是否返回如下?[self.name autorelease]; return self.name;
在setter函数中(也是自动生成的),
retain
ed对象是autorelease
d吗?-- (void) setName : (NSString *) someString { [someString retain]; [name release]; name = someString; /* [someString autorelease]; */ // performed internally? }
#import<Foundation/Foundation.h>
@interface Dog : NSObject
{@private NSString * name;}
@property (nonatomic,retain) NSString * name;
@end
@implementation Dog
@synthesize name;
- (id) init {
self = [super init];
if(self) {}
return self;
}
@end
int main(int argc, char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Dog * d = [[Dog alloc] init];
[d setName:@"Scooby"];
NSLog(@"Dog's name is: %@",[d name]);
[d release];
[pool drain];
return 0;
}