Why is my XCode template different?

Discussion in 'Mac Programming' started by chrono1081, Nov 18, 2011.

  1. chrono1081 macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #1
    Hi guys,

    I opened up XCode just now and started a foundation project and the code that popped up was this:

    Code:
    #import <Foundation/Foundation.h>
    
    int main (int argc, const char * argv[])
    {
    
        @autoreleasepool {
            
            // insert code here...
            NSLog(@"Hello, World!");
            
        }
        return 0;
    }
    
    Instead of this:

    Code:
    #import <Foundation/Foundation.h>
    
    int main (int argc, const char * argv[])
    {
    
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
            
        // insert code here...
        NSLog(@"Hello, World!");
            
        [pool drain];
        return 0;
    }
    
    I do not have ARC turned on, how come its different? It does it on both machines. Did something happen I'm not aware of?
     
  2. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #2
    Apple probably just wants you to get used to using the syntax. It does the same thing, just with less text (and more indent).
     
  3. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #3
    It does seem a little silly, though. You create an autorelease pool in main(), run the program, then drain the pool right before exiting. So, if you have something like a top or an emacs, that runs in a loop until you quit, you have main()'s pool sitting there probably empty because the inner runloop has created its own pool to keep things tidy. And when you exit, the heap just gets nuked anyway.
     
  4. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #4
    I think some things (which?) break if there's not an autorelease pool in effect. I think this is more about ensuring there always is an autorelease pool, and less about about actual memory management.
     
  5. chrono1081 thread starter macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #5
    Thanks guys for the responses :) I must have updated XCode and not realized it. The new template through me for a loop since I never saw that syntax before.
     

Share This Page