How does the NSAutoreleasePool autorelease pool work?
- by jsumners
As I understand it, anything created with an alloc, new, or copy needs to be manually released. For example:
int main(void) {
NSString *string;
string = [[NSString alloc] init];
/* use the string */
[string release];
}
My question, though, is wouldn't this be just as valid?:
int main(void) {
NSAutoreleasePool *pool;
pool = [[NSAutoreleasePool alloc] init];
NSString *string;
string = [[[NSString alloc] init] autorelease];
/* use the string */
[pool drain];
}