Re: literal strings - who do they belong to?
Re: literal strings - who do they belong to?
- Subject: Re: literal strings - who do they belong to?
- From: Bill Bumgarner <email@hidden>
- Date: Sun, 12 Jul 2009 09:02:13 -0700
On Jul 12, 2009, at 8:16 AM, William Squires wrote:
- (void)setWebView:(SomeAppDelegate *)appDelegate
{
NSString *htmlString;
htmlString = @"<div style=\"font-family;Helvetica,Arial, sans-serif;
font-size=48pt;\"align=\"center\">";
htmlString = [htmlString
stringByAppendingString:appDelegate.savedNumber];
htmlString = [htmlString stringByAppendingString:@"</span>"];
[webView loadHTMLString:htmlString baseURL:nil];
// [htmlString release]; // <- is this necessary?
}
After the second assignment, htmlString is no longer a literal string,
but will be a reference to whatever is returned by -
stringByAppendingString:.
That would be an autoreleased string so, no, the -release isn't
necessary.
The constant string -- the bits in @" ... " -- should be treated as -
autoreleased. That is, technically, you should -retain it if you
want it to stick around. However, the reality is that @"..." strings
are truly constant in that they are created as a part of compilation/
linking, are never really allocated as they are "just there", can't be
deallocated, and don't respond to retain/release/autorelease in the
normal way.
But, as Fritz said, treat 'em like regular old autoreleased objects.
b.bum
_______________________________________________
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