Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top