literal strings - who do they belong to?
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