Re: What's so special about NSString literals? (RE: memory management)
Re: What's so special about NSString literals? (RE: memory management)
- Subject: Re: What's so special about NSString literals? (RE: memory management)
- From: Eric <email@hidden>
- Date: Wed, 17 May 2006 19:56:25 -0700
Just ot make sure, so by "constant" you're referring to string literals
defined using the @"" notation right?
Are strings defined as NSString *string = [NSString stringWithFormat...]
constants as well? I mean, they are certainly immutable, but I'm not sure
if it's in the same class as string literals. If they are the same,
doesn't that mean I don't have to worry about releasing manually allocated
NSString like "string" as well?
Thanks
On 5/17/06, Lon Giese <email@hidden> wrote:
> So they are never deallocated throughout the program's lifetime?
right , thats what makes them constants, if you could dealloc them then
they would no longer be a constant...
I know its weird: a constant with an id, thats the magic of cocoa....
You can send retain and release to NSString constants but that has no
effect and is harmless...
its not that bad because constants are optimized by VM... they never
need to be paged out to disk because there is already a copy on disk,
they only need to be paged in when and if they are needed.
Do you have a massive number of NSString constants? is that why you
seem worried? you could use the plist editor and create an array of
@"strings" in a .plist file in the application package and load in the
NSArray when you need it... and dealloc it when you don't.. If you do
it that way the NSStrings would not be considered constants... This may
or may not be better depending on your application...
On May 17, 2006, at 9:48 AM, Eric wrote:
> So they are never deallocated throughout the program's lifetime?
>
> On 5/15/06, Nick Zitzmann <email@hidden> wrote:
>>
>>
>> On May 15, 2006, at 9:15 PM, Eric wrote:
>>
>> > I'm just curious as to why when NSStrings are created using literal
>> > (as in
>> > @"a string"), I never have to worry about retaining it or releasing
>> > it.
>> > What's so special about it?
>>
>> They're stored as constant strings in the binary. They'll exist in
>> memory as long as the program is running.
>>
>> Nick Zitzmann
>> <http://www.chronosnet.com/>
>>
>>
>>
>>
>>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
> email@hidden
>
> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden