Users Pricing

forum

home / developersection / forums / nsautorelease pool how it works

NSAutorelease pool how it works

Tarun Kumar 1979 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];

}

Tarun Kumar

Other


1 Answers