On Jun 12, 2008, at 10:21 AM, Jeff LaMarche wrote:
Lately, I've started to see accessors of the following sort:

- (NSString *)foo
{
        return [[foo retain] autorelease];
}

rather than just

- (NSString *)foo
{
        return foo;
}

What is the purpose or benefit of doing this? It seems to me that this would add things unnecessarily to the autorelease pool, and I can't see a benefit to be had. I've seen it in places that make me think there must be a reason (e.g. sample code from Apple), so I'm guessing I'm missing something. Is there some benefit due to GC? If so, should this construct be used without GC or only with?

Assuming there is a -setFoo: that is implemented as retain-new / release-old, as is typical...

Consider:

id b = [something foo];
[something setFoo: @"bar"];
[b length];

The above will crash in the non retain/autorelease case, but not otherwise.

b.bum

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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