Question

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.

Was it helpful?

Solution

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

OTHER TIPS

I think I don't get your question. Anyway you could google it what it does or for what its needed or read a book on ios development ;) The autoreleasepool handles all your memory issues, when you are using ARC (Automatic Reference Counting). So you dont need a void dealloc method to do it and release everything at the hand manually. This goes for main, as for seperates thread inside your app. The autoreleasepool takes care of all of them. Hope that answers your question. Short, but simple.

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