I’ve read some documentation on what autorelease does and the common use cases. I understand this is how most people describe it: “The autorelease pool is typically released after each iteration of the run loop.”
What exactly constitutes an iteration of the run loop? Sorry, but this explanation confuses the heck out of me ’cause it sounds quite abstract…
Is an iteration when it returns from a function? Does that mean any object with autorelease is a local variable?
The easiest way to think about it is like this:
A run loop ends when a method finishes that your code didn’t explicitly call. That’s when autorelease objects are released. (This is a slight oversimplification.)
If you think carefully about your code, there are many entry points that you don’t call. These include reactions to the user pressing a UIControl, loadView or viewDidLoad on UIViewController subclasses, methods called by an NSTimer, or things you call using
performSelector:withObject:afterDelay:. There is basically a big loop in the sky that does something like this (very rough pseudocode here):I’m sure the actual code is better written than that, but that can give you a general idea of what a run loop is. Also, check out this post.