据我了解,任何使用alloc,new或copy创建的东西都需要手动释放.例如:
int main(void) {
NSString *string;
string = [[NSString alloc] init];
/* use the string */
[string release];
}
Run Code Online (Sandbox Code Playgroud)
不过,我的问题是,这不是有效吗?:
int main(void) {
NSAutoreleasePool *pool;
pool = [[NSAutoreleasePool alloc] init];
NSString *string;
string = [[[NSString alloc] init] autorelease];
/* use the string */
[pool drain];
}
Run Code Online (Sandbox Code Playgroud) memory-management foundationkit objective-c nsautoreleasepool