NSString memory management question
-
I wrote a routine that creates a CFStringRef from some USB calls. I
use it like this:
NSString* s = (NSString*) createStringDescriptor(dev, stringIndex);
[mSerialNumberDisplay setStringValue: [s lowercaseString]];
[s release];
Two main questions: am I right to release the bridged NSString* s?
and, what happens in -lowercaseString? How does that get released?
TIA,
--
Rick -
On Tue, Apr 22, 2008 at 3:25 PM, Rick Mann <rmann...> wrote:> I wrote a routine that creates a CFStringRef from some USB calls. I use it
> like this:
>
> NSString* s = (NSString*) createStringDescriptor(dev, stringIndex);
> [mSerialNumberDisplay setStringValue: [s lowercaseString]];
> [s release];
>
>
> Two main questions: am I right to release the bridged NSString* s? and,
We don't know how you created the CFStringRef so we cannot say. The
answer depends on the create/get rule of the Core Foundation method
you used. Additionally it depends on the contract you want to present
to clients for the createStringDescriptor.> what happens in -lowercaseString? How does that get released?
Review...
<http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/
MemoryManagementRules.html>
-Shawn -
On Apr 22, 2008, at 3:51 PM, Shawn Erickson wrote:> We don't know how you created the CFStringRef so we cannot say. The
> answer depends on the create/get rule of the Core Foundation method
> you used. Additionally it depends on the contract you want to present
> to clients for the createStringDescriptor.
Sorry, I thought saying "created" was clear. I actually call a
CreateXXX function.>> what happens in -lowercaseString? How does that get released?> >
>
> Review...
>
> <http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/
MemoryManagementRules.html
Okay, I think from that, the string is automagically freed. Thanks!
--
Rick -
Am 23.04.2008 um 00:25 schrieb Rick Mann:> I wrote a routine that creates a CFStringRef from some USB calls. I
> use it like this:
>
> NSString* s = (NSString*) createStringDescriptor(dev, stringIndex);
> [mSerialNumberDisplay setStringValue: [s lowercaseString]];
> [s release];
>
> Two main questions: am I right to release the bridged NSString* s?
> and, what happens in -lowercaseString? How does that get released?
Calling release on a CFString follows the same rules as calling it
on an NSString*, and is equivalent to calling CFRelease(). Be careful,
though, if you get a CFString or OSString from IOKit ... someone there
apparently wasn't told about the rules in the rest of
CoreFoundation... they don't follow the Create/Copy naming scheme
consistently, and instead have weird phrases in the docs about
"consuming a refcount" and things like that.
But apart from that, the rules in the CoreFoundation docs apply, so
assuming you're using a CFStringCreateXXX call, yes, you should
release this string.
Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de -
On Apr 22, 2008, at 5:46 PM, Uli Kusterer wrote:> But apart from that, the rules in the CoreFoundation docs apply, so
> assuming you're using a CFStringCreateXXX call, yes, you should
> release this string.
Yeah, I was fairly sure about that one, it was the NSString -
lowercaseString I wasn't sure about.
--
Rick


