Possible Duplicate:
NSString retain Count
I am the beginner for iPhone programming. I am dealing with NSString. I got a doubt explained below.
@implementation Sample;
NSString *str;
-(void)viewDidLoad
{
str = [[NSString alloc] initWithString:@"Hello"];
// Why retain count is some random value? (Eg.2147234)
NSLog(@"retain count of string %d",[str retainCount]);
[str release];
}
-(void)printString
{
// Why the value for "str" getting printed here,
// though its released in viewDidLoad?
NSLog(@"string is %@",str);
}
Don’t look at
retainCount. It’ll confuse you, and it doesn’t help.Constant strings are built right into the code — they’re never allocated or released. It’s fine for you to retain and release them as you would any other object, but don’t expect a constant string to be deallocated at any point.