NSAutoreleasePool 和 @autoreleasepool blocks 區別


//
// 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; }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM