When I create an NSString with the initWithFormat, I get the number to hold 1
< Pre> - (NSString *) Description {NSString * descr = [[NSString alloc] initWithFormat: @ "I have a description."]; NSLog (@ "Count:% lu", [descr retainCount]); Return [descr autorelease]; } If I use initWithString, I get a number of 2147483647
NSString * descr = [[NSString alloc] initWithString: @ " I have the details. "]; Therefore, there should be a difference between these two methods in terms of memory management. What's going on here First of all, you should keep in mind that what is the number of retaining, whether you have your -init , -copy and -retain message -release or -autoorelus message.
It is being said that when you make a NSString example by parse a format string, memory is allocated for it. When you make a string by referencing a constant string in your code, you end up with an indicator in a constant string, and the number of maintenance it will normally appear in as UINT_MAX. This is an implementation statement that you do not have to worry about.
Comments
Post a Comment