Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>ARC doesn't get rid of retains, releases and autoreleases, it just adds in the required ones for you. So there are still calls to retain, there are still calls to release, there are still calls to autorelease and there are still auto release pools.</p> <p>One of the other changes they made with the new Clang 3.0 compiler and ARC is that they replaced <code>NSAutoReleasePool</code> with the <code>@autoreleasepool</code> compiler directive. <code>NSAutoReleasePool</code> was always a bit of a special "object" anyway and they made it so that the syntax of using one is not confused with an object so that it's generally a bit more simple.</p> <p>So basically, you need <code>@autoreleasepool</code> because there are still auto release pools to worry about. You just don't need to worry about adding in <code>autorelease</code> calls.</p> <p>An example of using an auto release pool:</p> <pre><code>- (void)useALoadOfNumbers { for (int j = 0; j &lt; 10000; ++j) { @autoreleasepool { for (int i = 0; i &lt; 10000; ++i) { NSNumber *number = [NSNumber numberWithInt:(i+j)]; NSLog(@"number = %p", number); } } } } </code></pre> <p>A hugely contrived example, sure, but if you didn't have the <code>@autoreleasepool</code> inside the outer <code>for</code>-loop then you'd be releasing 100000000 objects later on rather than 10000 each time round the outer <code>for</code>-loop.</p> <p><strong>Update:</strong> Also see this answer - <a href="https://stackoverflow.com/a/7950636/1068248">https://stackoverflow.com/a/7950636/1068248</a> - for why <code>@autoreleasepool</code> is nothing to do with ARC.</p> <p><strong>Update:</strong> I took a look into the internals of what's going on here and <a href="http://www.galloway.me.uk/2012/02/a-look-under-arcs-hood-episode-3/" rel="noreferrer">wrote it up on my blog</a>. If you take a look there then you will see exactly what ARC is doing and how the new style <code>@autoreleasepool</code> and how it introduces a scope is used by the compiler to infer information about what retains, releases &amp; autoreleases are required.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload