Tag: 套件

NSAutoreleasePool autorelease池如何工作?

据我所知,用alloc , new或copy创build的任何东西都需要手动发布。 例如: 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]; }