If you think about it, it becomes clear why convenience methods return autoreleased objects. As a heuristic, whoever retains an object should release it. Since you're having the class method perform an implicit retain (by calling alloc) then it needs to do a release. It obviously cannot release the object before returning it to you, so its only choice is to autorelease. When you call alloc yourself, then you are the one responsible for releasing at a later time.

Luke


On Nov 20, 2008, at 5:57 PM, Dave DeLong wrote:


On 20 Nov, 2008, at 6:54 PM, Klaus Backert wrote:

"Class factory methods are implemented by a class as a convenience for clients. They combine allocation and initialization in one step and return the created object autoreleased. These methods are of the form + (type)className... (where className excludes any prefix)."

"autoreleased" !

Because of this the following statements are identical, as far as I can see:

NSString *blah = [[[NSString alloc] init] autorelease];
NSString *blah = [NSString string];

Aren't they?

Yes.  They are identical.

Dave
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/luketheh%40apple.com

This email sent to [EMAIL PROTECTED]

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to