I asked about this a few days ago, and I thought the general answer was
that if I get an object as the return value of a function, it has already
been autoreleased and I don't have to release it myself. However, the
following code (which is from an email I posted earlier today on a
different topic), is taken from the docs and shows a returned object being
released when I am done with it:
int dropMethod = 0;
CFStringRef dropMethodKey = CFSTR("dropMethod");
CFNumberRef dropMethodVal = CFPreferencesCopyAppValue(dropMethodKey,
kCFPreferencesCurrentApplication);
if (dropMethodVal)
{
if (!CFNumberGetValue(dropMethodVal, kCFNumberIntType,
&dropMethod))
dropMethod = 0;
CFRelease(dropMethodVal);
}
else dropMethod = 0;
So, how do I know if an object that has been returned from a function call
(message, whatever it's called) needs to be released when I'm
done using it? In some cases, if I release the returned object of a
function, I get a warning suggesting I shouldn't be releasing it, but in
other cases, as shown above, a similar situation requires releasing such
an object.
I'm not detecting the pattern here.
Thanks.
________________________________________________________________________
Keith Wiley kwiley@cs.unm.edu http://www.unm.edu/~keithw
"Yet mark his perfect self-contentment, and hence learn his lesson,
that to be self-contented is to be vile and ignorant, and that to
aspire is better than to be blindly and impotently happy."
-- Edwin A. Abbott, Flatland
________________________________________________________________________
Doug Brown - 16 Aug 2005 23:54 GMT
> CFNumberRef dropMethodVal = CFPreferencesCopyAppValue(dropMethodKey,
>
[quoted text clipped - 4 lines]
> other cases, as shown above, a similar situation requires releasing such
> an object.
The function you used, CFPreferencesCopyAppValue(), has Copy in the name.
That means you're responsible for releasing the returned object. The way
to tell is to look at the function name. Two of the words for which you're
looking are Copy and Create.
Hope this helps :)
Doug

Signature
Doug Brown - La Grande, Oregon
http://www.doogul.com/
Keith Wiley - 17 Aug 2005 01:25 GMT
>> CFNumberRef dropMethodVal = CFPreferencesCopyAppValue(dropMethodKey,
>>
[quoted text clipped - 9 lines]
> to tell is to look at the function name. Two of the words for which you're
> looking are Copy and Create.
Cool. Thanks.
________________________________________________________________________
Keith Wiley kwiley@cs.unm.edu http://www.unm.edu/~keithw
"Yet mark his perfect self-contentment, and hence learn his lesson,
that to be self-contented is to be vile and ignorant, and that to
aspire is better than to be blindly and impotently happy."
-- Edwin A. Abbott, Flatland
________________________________________________________________________