On Sat, Sep 6, 2008 at 5:06 PM, I. Savant <[EMAIL PROTECTED]> wrote: > On Sep 6, 2008, at 7:06 PM, Finlay Dobbie wrote: > >> Why the unnecessary copy? >> >> - (NSString *)uuid >> { >> CFUUIDRef uuidRef = CFUUIDCreate(NULL); >> CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef); >> CFRelease(uuidRef); >> return [(NSString *)uuidStringRef autorelease]; >> } > > > I didn't write or verify the code, but you appear to be absolutely right. > Maybe you'd like to update the wiki?
The original works with both GC and non-GC, while the version with autorelease will leak under GC (because the string is never CFRelease'd). In order to work with both runtimes, either use the original, or do this: - (NSString *)uuid { CFUUIDRef uuidRef = CFUUIDCreate(NULL); CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef); CFRelease(uuidRef); return [NSMakeCollectable(uuidStringRef) autorelease]; } -- Clark S. Cox III [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]