Re: Zones, [[alloc] init], and all the new + methods
Re: Zones, [[alloc] init], and all the new + methods
- Subject: Re: Zones, [[alloc] init], and all the new + methods
- From: "John C. Randolph" <email@hidden>
- Date: Wed, 26 Dec 2001 13:28:18 -0800
On Wednesday, December 26, 2001, at 09:06 AM, Simson Garfinkel wrote:
>
I've noticed that Apple is now shying away from [[<CLASS> alloc] init]
>
and has instead created a whole bunch of [<CLASS> <class>]
>
constructors.
>
>
For example, instead of using
>
>
id dict = [[NSMutableDictionary alloc] init];
>
>
to create a dictionary, the correct approach is now:
>
>
id dict = [NSMutableDictionary dictionary];
>
>
Similarly, instead of
>
>
id path = [[NSBezierPath alloc] init]
Actually, this is correct, too.
>
>
We are now to use:
>
>
id path = [NSBezierPath bezierPath];
>
>
Can anyone share with me the logic for this?
The alloc-init sequence is still there, and it won't be going
away. The convenience constructors you mention return
autoreleased instances, so you can use them without bothering
with -release messages.
>
One of the big advantage of the [[<class> alloc] init] approach
>
is that it very easily became [[<class> allocFromZone:myZone] init]
And that advantage is still there..
-jcr
"Computers in the future may weigh no more than 1.5 tons." -
Popular Mechanics, 1949