I have the following piece of code:
NSString *tempString = [[NSString alloc] initWithFormat:@"%d/%d/%d",day, month, year];
dateString = tempString;
[tempString release];
NSLog(@"retain count for datstring and tempstring is %d and %d",[dateString retainCount],[tempString retainCount]);
NSLog(@"%@ and %@",dateString, tempString)
Now it prints the retain count of tempString as 1 (also dateString retain count = 1) even though I am releasing it in the line before. Also the NSlog statement printing the two strings doesn't display anything. Im assuming this is because, since by my code, dateString is pointing to the location of tempString and tempString has been released, NSlog will be unable to print the string. But then why is the retain count of tempString = 1?
If i replace the line
dateString = tempString;
with
dateString = [NSString stringWithString: tempString];
then the NSlog statement prints the values of both dateString and tempString and displays their retain counts as 1. How is the value of tempString getting printed when i am releasing it in the previous line?