【发布时间】:2010-09-09 02:08:06
【问题描述】:
据我了解,使用 alloc、new 或 copy 创建的任何内容都需要手动释放。例如:
int main(void) {
NSString *string;
string = [[NSString alloc] init];
/* use the string */
[string release];
}
不过,我的问题是,这不是同样有效吗?:
int main(void) {
NSAutoreleasePool *pool;
pool = [[NSAutoreleasePool alloc] init];
NSString *string;
string = [[[NSString alloc] init] autorelease];
/* use the string */
[pool drain];
}
【问题讨论】:
标签: objective-c memory-management nsautoreleasepool foundationkit