PDA

View Full Version : NSAutoReleasePool




teguh123
Mar 30, 2011, 04:06 AM
Why do we use



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

NSAutoreleasePool * pool = [NSAutoreleasePool new];



jnoxx
Mar 30, 2011, 04:09 AM
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
Mar 30, 2011, 05:45 AM
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
Mar 30, 2011, 11:28 AM
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
Mar 30, 2011, 11:40 AM
Also, a lot of times there are extensions to init (for example, initWithString:) but no corresponding extension to new.

jnoxx
Mar 31, 2011, 04:06 AM
Also, a lot of times there are extensions to init (for example, initWithString:) but no corresponding extension to new.

Thanks for that :)
Allways usefull reading these topics!