• 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
literal strings - who do they belong to?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

literal strings - who do they belong to?


  • Subject: literal strings - who do they belong to?
  • From: William Squires <email@hidden>
  • Date: Sun, 12 Jul 2009 10:16:47 -0500

According to Cocoa/ObjC memory-management, if you get an object (reference) via "alloc","new",any object that contains "copy", and any object you send [<object> retain] to, is yours - it becomes your responsibility to call [<your object> release] on it when you're done. Ditto for properties like

@property (nonatomic,retain) <data type>myProp;

where "retain" is specified.

But what about literal NSStrings?

I have a method in my view controller class.

- (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?
}


For reference, SomeAppDelegate.h declares "savedNumber" as a property like the above. i.e.

@interface SomeAppDelegate : NSObject <UIApplicationDelegate>
{
NSString *savedNumber;
}

@property (nonatomic,retain) NSString *savedNumber;
@end

and is synthesized in SomeAppDelegate.m:
@implementation SomeAppDelegate

@synthesize savedNumber
...
@end

Does the setWebView: method need an [htmlString retain] somewhere? Does [NSString stringByAppendingString] do anything funny I should know about?

_______________________________________________

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: Jeff Laing <email@hidden>
    • Re: literal strings - who do they belong to?
      • From: Ben Cox <email@hidden>
    • Re: literal strings - who do they belong to?
      • From: Bill Bumgarner <email@hidden>
    • Re: literal strings - who do they belong to?
      • From: Fritz Anderson <email@hidden>
  • Prev by Date: Re: Undo without Redo
  • Next by Date: Re: literal strings - who do they belong to?
  • Previous by thread: Re: Undo without Redo
  • Next by thread: Re: literal strings - who do they belong to?
  • Index(es):
    • Date
    • Thread