NSString +stringByAppendingString:(NSString*) returns an autoreleased string. If you release it explicitly, your application will crash. -- Ben
On Sun, Jul 12, 2009 at 11:16 AM, William Squires <wsqui...@satx.rr.com>wrote: > 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 (Cocoa-dev@lists.apple.com) > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/cox%40djehuti.com > > This email sent to c...@djehuti.com > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com