NSAutoReleasePool

Discussion in 'iOS Programming' started by teguh123, Mar 30, 2011.

  1. macrumors member

    Joined:
    Mar 22, 2011
    #1
    Why do we use



    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]init];
    Why not

    NSAutoreleasePool * pool = [NSAutoreleasePool new];
     
  2. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    Well, mostly, alloc init, is for creating the memory part where it's gonna put it, like every other object (nearly). there is a biiig explenation about this, i'm sure some of these guys can exactly tell you, it's something with bits on the heap stack, and blah x) But it all comes down to memory management.
     
  3. thread starter macrumors member

    Joined:
    Mar 22, 2011
    #3
    I thought new is just a short for alloc init

    Both seems to work just fine. It's just choice it seems
     
  4. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    That's right. Functionally alloc/init and new are the same. It's a style difference. new is not popular. Most old timers prefer to use alloc/init because it's more clear what's going on.
     
  5. dejo, Mar 30, 2011
    Last edited: Mar 30, 2011

    Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Also, a lot of times there are extensions to init (for example, initWithString:) but no corresponding extension to new.
     
  6. macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #6
    Thanks for that :)
    Allways usefull reading these topics!
     

Share This Page