objective-c - NSAutoreleasePool和autoreleasepool的区别
ringa_lee
ringa_lee 2017-04-21 11:16:28
0
2
365

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.

xcode4.3引入ARC,release这块就有些变化,当你使用ARC,就必须将NSAutoreleasePool的地方换成 @autoreleasepool

http://marshal.easymorse.com/archives...

ringa_lee
ringa_lee

ringa_lee

모든 응답(2)
伊谢尔伦

두 사람의 행동 시간이 다릅니다. AutoReleasePool 객체의 쓰기 방법은 런타임에 작동하고 @autoreleasepool은 컴파일 단계에 작동합니다. ARC를 활성화하려면 런타임에 동적으로 추가하는 대신 컴파일 단계에서 자동 참조 계산 관리를 활성화하도록 컴파일러에 지시해야 합니다.

小葫芦

이제 Apple에서는 ARC 사용 여부에 관계없이 @autoreleasepool{} 사용을 권장합니다

@autoreleasepool 블록은 > NSAutoreleasePool 인스턴스를 직접 사용하는 것보다 더 효율적입니다. ARC를 사용하지 않더라도 사용할 수도 있습니다. http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSAutoreleasePool_Class/Reference/Reference.html

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!