• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: literal strings - who do they belong to?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: literal strings - who do they belong to?
      • From: Peter N Lewis <email@hidden>
References: 
 >literal strings - who do they belong to? (From: William Squires <email@hidden>)

  • Prev by Date: Re: literal strings - who do they belong to?
  • Next by Date: Re: How to prevent NSTableView from reordering rows when clicking at a header cell?
  • Previous by thread: Re: literal strings - who do they belong to?
  • Next by thread: Re: literal strings - who do they belong to?
  • Index(es):
    • Date
    • Thread