Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

teguh123

macrumors member
Original poster
Mar 22, 2011
62
0
Why do we use



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

NSAutoreleasePool * pool = [NSAutoreleasePool new];
 

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
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.
 

teguh123

macrumors member
Original poster
Mar 22, 2011
62
0
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.

I thought new is just a short for alloc init

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

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Also, a lot of times there are extensions to init (for example, initWithString:) but no corresponding extension to new.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.