相关疑难解决方法(0)

NSAutoreleasePool自动释放池如何工作?

据我了解,任何使用alloc,newcopy创建的东西都需要手动释放.例如:

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

95
推荐指数
4
解决办法
9万
查看次数