Note that there are some explanatory texts on larger screens.

plurals
  1. POAutorelease pools and when release is called under iOS
    text
    copied!<p>I wanted to get something clarified.</p> <p>Lets say I have the following code:</p> <pre><code>- (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; for (int i = 0; i &lt; 5000000; i++) { NSString *s = [NSString stringWithFormat:@"Hello, %@!", @"World"]; } } </code></pre> <p>This will create 5 million autoreleased strings within this function call. I was expecting this to keep those objects around until the termination of the application, as the only @autoreleasepool I see is the one wrapping the application instantiation in main.m. That's not the case, though. At the end of this function call, it seems they all get their release called and are removed from memory.</p> <p>This document:</p> <p><a href="https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/Classes/NSAutoreleasePool_Class/Reference/Reference.html" rel="noreferrer">https://developer.apple.com/library/mac/documentation/cocoa/reference/foundation/Classes/NSAutoreleasePool_Class/Reference/Reference.html</a></p> <p>States that "The Application Kit creates an autorelease pool on the main thread at the beginning of every cycle of the event loop, and drains it at the end, thereby releasing any autoreleased objects generated while processing an event."</p> <p>That makes sense to me, but this is under UIKit, and not Application Kit. My question is, does UIKit/Cocoa Touch do the same thing in this case, or is there another explanation for my objects getting released?</p> <p>Thanks!</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