• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to create a GUID?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to create a GUID?


  • Subject: Re: How to create a GUID?
  • From: "Clark Cox" <email@hidden>
  • Date: Sat, 6 Sep 2008 19:51:01 -0700

On Sat, Sep 6, 2008 at 5:06 PM, I. Savant <email@hidden> 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@hidden
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: How to create a GUID?
      • From: "Sean McBride" <email@hidden>
    • Re: How to create a GUID?
      • From: Klaus Backert <email@hidden>
References: 
 >How to create a GUID? (From: Meik Schuetz <email@hidden>)
 >Re: How to create a GUID? (From: "I. Savant" <email@hidden>)
 >Re: How to create a GUID? (From: "Finlay Dobbie" <email@hidden>)
 >Re: How to create a GUID? (From: "I. Savant" <email@hidden>)

  • Prev by Date: Re: new to Cocoa -- threading question
  • Next by Date: Re: How to create a GUID?
  • Previous by thread: Re: How to create a GUID?
  • Next by thread: Re: How to create a GUID?
  • Index(es):
    • Date
    • Thread