forum

Home / DeveloperSection / Forums / NSAutorelease pool how it works

NSAutorelease pool how it works

Tarun Kumar 1598 10-Aug-2015

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];

}

Updated on 11-Aug-2015

Can you answer this question?


Answer

1 Answers

Liked By