Skip navigation.
 
mlRe: Memory management with CF Objects
FROM : Rosyna
DATE : Fri Jan 03 15:36:01 2003

IN CF, if something is returned from a function containing the words
"Copy" or "Create" then you must release it. Your code could be:

NSString* uuid = [(NSString *)CFUUIDCreateString(0, CFUUIDCreate(0))
autorelease];

For readability, you might want to use NULL instead of 0 in the above function.

CF functions containing neither of these words do not need to be
released. Like CFDictionaryGetValue().

This *only* applies to CF objects being returned from CF calls!

ATSGetFontName gives you a new CFStringRef that you *must* release.
It does not start with CF so it does not follow the CF rule. You have
to guess with these cases most of the time..


Ack, at 1/3/03, Armin Briegel said:

>I am confused but mainly because of my lack of knowledge in Carbon
>and Core Foundation. I'd like to use the CF to generate UUIDs in the
>following manner.
>
>        uuid = (NSString *)CFUUIDCreateString(0, CFUUIDCreate(0));
>
>(uuid id of course an NString *) Now should I consider the object
>returned by the CFUUIDCreateString() function to be retained of
>autoreleased? If it is retained should I consider the object
>returned by the CFUUIDCreate() function retained as well? So I have
>to release it? Should the above code actually look like this:
>
>        CFUUIDRef cfuuid = CFUUIDCreate(0);
>        uuid = (NSString *)CFUUIDCreateString(0, cfuuid);
>        CFRelease(cfuuid);
>
>or rather like this?
>
>        uuid = (NSString *)CFUUIDCreateString(0, CFUUIDCreate(0));
>        [uuid retain];
>
>confused


--


Sincerely,
Rosyna Keller
Technical Support/Holy Knight/Always needs a hug

Unsanity: Unsane Tools for Insanely Great People
---

Please include any previous correspondence in replies, it helps me
remember what we were talking about. Thanks.

Related mailsAuthorDate
mlMemory management with CF Objects Armin Briegel Jan 3, 04:50
mlRe: Memory management with CF Objects Finlay Dobbie Jan 3, 04:59
mlRe: Memory management with CF Objects Rosyna Jan 3, 15:36
mlRe: Memory management with CF Objects Jim Correia Jan 3, 15:44
mlRe: Memory management with CF Objects Rosyna Jan 3, 20:52