Possible Duplicate:
Does every thread need its own autorelease pool?
I would like to know why it is required to use autorelease pool, when we call some methods on a separate thread rather than the main thread, please clarify.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you’re using garbage collection EXCLUSIVELY in the thread you don’t need an autorelease pool for it.
However, if you’re manually managing retain counts (managed memory model) at all, even if you’re using it with garbage collection as well, then each thread DOES need it’s own autorelease pool.
Autorelease pools are thread-specific, that is a pool from thread A can’t access/manage a pool from thread B. Typically each thread will have multiple autorelease pools to lessen memory usage. Again, nested pools are specific to their thread – they can’t manage memory from other threads.
You should read up on the the iOS threading guide at https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Multithreading/
Also, Apple is recommending migrating away from threading and managing concurrency with Grand Central Dispatch. It’s a fair bit easier to do, IME, for anything complicated:
https://developer.apple.com/library/ios/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/ThreadMigration/ThreadMigration.html#//apple_ref/doc/uid/TP40008091-CH105-SW1