Cocoa Development: When does an autorelease pool get deallocated?
-
It's a question with many answers on the internet, but it's kind of hard to get around it. Can someone explain it nicely?
-
Answer:
NSAutoeleasePool objects are under the same Memory-Management rules like any other object. The catch here is that a pool may not be an autorelease object and you may not retain it, either. On iOS (that doesn't have GC), calling 'drain' and 'release' on your autorelease pool are effectively the same thing - that means that your pool gets deallocated the moment you call 'drain' on it. Calling release and drain are exactly the same thing, but if you call release in an NSAutoreleasePool you created, it may throw off the developer who has to maintain your code. Things are a bit different when you are working in GC environments (Mac OS X, as a relevant example). In a GC environment, there's no use to have autorelease pools. However, if you are writing a program for GC environments but plan on giving it support for non-GC environments, you cannot call 'release' on an autorelease pool, but you may freely call 'drain' on it, and the moment you do that, you are actually triggering Garbage Collection, rather than draining the 'pool' itself. Hope this is clear enough. If something is not clear, feel free to ask.
Andrés Ibañez at Quora Visit the source
Related Q & A:
- How do I get a job in IT or Software Development if I have no experience and only a 3rd class degree?Best solution by answers.yahoo.com
- When am I going to get my package?Best solution by my.usps.com
- Why is my pool always cloudy when opened?Best solution by Yahoo! Answers
- Why is it so cold when you first get in the pool?Best solution by Yahoo! Answers
- Things to do in the summer when you don't have a pool?Best solution by viralnova.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.