据我理解,任何使用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];
}
for
或while
那样是一种语言结构。相反,它是一种调度机制,用于管理线程内的不同执行状态和事件。 - user529758