Possible Duplicate:
ARC memory leaks

Can we use @autorelease pool in ARC enabled projects. If so, what is the use of using @autorelease pool. I found in google that, even if the project is ARC enabled, it will be taking care of only main thread. If we create other threads, then we have to take care of releasing objects. Can anyone explain

有帮助吗?

解决方案

When you migrate from manual memory management to ARC you will replace the:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[pool release];

With

@autoreleasepool {

    }

Read the NSAutoreleasePool docs and Advanced Memory Management Programming Guide for a better understanding.

其他提示

Yes, ARC is only set up on the main thread by default. However, you can also take advantage of it inside background threads. The solution is simple: the semantics of the @autoreleasepool { } is different for ARC; it doesn't actually allocate and release an NSAutoreleasePool object the classic MRC way, it simply tells ARC to take care of the objects in the tread in which it was called as well, achieving an autorelease pool-style effect.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top