I used following link for understand the retain count.
retain count in iphone
As per that question output is :
NSString *str = [[NSString alloc] initWithFormat:@"a,b,c,d"];
NSArray *anArray =[[NSArray alloc]init];
NSLog(@"Retain count: %i", [anArray retainCount]);
anArray=[str componentsSeparatedByString:@","];
NSLog(@"Retain count: %i", [anArray retainCount]);
OUTPUT
Retain count: 2
Retain count: 1
When I tried this code in my example :
NSString *str = [[NSString alloc] initWithFormat:@"a,b,c,d"];
NSArray *anArray=[[NSArray alloc]init];
NSLog(@"Retain count: %i", [anArray retainCount]);
anArray=[str componentsSeparatedByString:@","];
NSLog(@"Retain count: %i", [anArray retainCount]);
Then OUTPUT is
Retain count: 51
Retain count: 1
I can't understand why the retain count of NSArray
is 51 and after assigning value in array it becomes 1.
I also read
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html
http://ranga-iphone-developer.blogspot.in/2011/11/what-is-retain-count-or-reference.html
iOS about retainCount
and other tutorial. but I can't understand the value of Retain count: 51
.
Pleas Help me.
Thank You.