您的位置:首页 > 其它

NSAutoreleasePool 和 @autoreleasepool blocks 区别

2013-06-28 00:30 507 查看
转载地址:http://www.cnblogs.com/PirateCaptain/articles/2506330.html

//
//  main.m
//  HelloWorld
//
//  Created by Erica Sadun on 4/24/09.
//  Copyright __MyCompanyName__ 2009. All rights reserved.
/**
xcode4.3引入ARC,release这块就有些变化,当你使用ARC,就必须将NSAutoreleasePool的地方换成 @autoreleasepool
关于NSAutoreleasePool的解释官方的最清楚
Important If you use Automatic Reference Counting (ARC), you cannot use autorelease pools directly. Instead, you use @autoreleasepool blocks instead. For example, in place of:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init;
// Code benefitting from a local autorelease pool.
[pool release];
you would write:
@autoreleasepool {
// Code benefitting from a local autorelease pool.
}
@autoreleasepool blocks are more efficient than using an instance of NSAutoreleasePool directly; you can also use them even if you do not use ARC.
**/

#import <UIKit/UIKit.h>
#import "HelloWorldAppDelegate.h"  //如果下面第二个参数直接用nil,不用import这个Delegate.h头文件也可

int main(int argc, char *argv[]) {

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog(@"nil如何调用窗口呢");

int retVal = UIApplicationMain(argc, argv, nil,nil); //等效下一句,第二个nil表示就把模板生成的Delegate类作为默认参数

//int retVal = UIApplicationMain(argc, argv, nil,NSStringFromClass([HelloWorldAppDelegate class]));

[pool release];
return retVal;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: