title: Why doesn't an iPhone app's main() function ever get a chance to finish?
body: <p>Consider the following <code>main()</code> method which you would find most iPhone applications:</p>
  
  <pre><code>int main(int argc, char *argv[])
  {
      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
      int retVal = UIApplicationMain(argc, argv, nil, nil);
      [pool release];
      return retVal;
  }</code></pre>
  
  <p>In every iPhone app that I've run in Simulator with these (including several sample projects provided by Apple), the thread never exits <code>UIApplicationMain()</code> and any remaining code in <code>main()</code> is never executed. Is this expected behavior? </p>
  
  <p>I have verified that statements after <code>UIApplicationMain()</code> never run by stepping through the code with a debugger. When the user stops an application (by hitting the "Home" button, for example), the resulting stack trace shows that  <code>[UIApplication _terminateWithStatus:]</code> is eventually called. This function calls your application delegate's <code>applicationWillTerminate:</code> method. Once that finishes, <code>[UIApplication _terminateWithStatus:]</code> seems to kill/exit the thread.</p>
  
  <p>Can someone confirm that this is how <code>main()</code> is supposed to work, or at least confirm the same behavior on their machine?</p>