문제

I read somewhere that when we use @autoreleasepool { } blocks with ARC enabled, the compiler generates code to get the objc_autoreleasePoolPush() and objc_autoreleasePoolPop() functions called at the beginning and at the end of the block, respectively.

However, when I compile an Objective-C file with @autoreleasepool blocks, these two functions don't get called, even with -fobjc-arc. Instead, the compiler generates code to allocate a new NSAutoreleasePool object (with something equivalent to [[NSAutoreleasePool alloc] init]) at the beginning and to drain the pool (with a -drain call) at the end of the block.

So, are the objc_autoreleasePoolPush() and objc_autoreleasePoolPop() functions really supposed to be called with ARC enabled? If yes, what compiler options are missing?

도움이 되었습니까?

해결책

objc_autoreleasePoolPush() and objc_autoreleasePoolPop() are really supposed to be called at the beginning and at the and of an @autoreleasepool block, respectively, from the code generated by the compiler, starting from OSX 10.7/ iOS 5.0. The missing compiler option is -fobjc-runtime=macosx-10.7.

And, by the way, ARC has nothing to do with all this, so that @autoreleasepool blocks make the compiler generate calls to those two functions even with ARC not enabled.

다른 팁

What's your deployment target set to? It may need to be OSX 10.8/iOS 6 to get the newer way of doing things.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top