代码请在main函数下写
不然出来的东西千奇百怪。
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
写在这:
NSData *str=[[NSData alloc]init];
NSLog(@" strretainCount == %d",[str retainCount]);
NSData *str1= [[NSData alloc]init];
NSLog(@"str1 retainCount == %d",[str1 retainCount]);
NSData *arr= [[NSData alloc]init];
NSLog(@" arrretainCount == %d",[arr retainCount]);
NSData *arr1= [[NSData alloc]init];
NSLog(@"arr1 retainCount == %d",[arr1 retainCount]);
NSData *arr2= [[NSData alloc]init];
NSLog(@"arr2 retainCount == %d",[arr2 retainCount]);
这个应该都是1,很对;
那么下边那
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray*str=[[NSArray alloc] init];
NSLog(@" strretainCount == %d",[str retainCount]);
NSArray*str1 = [[NSArray alloc]init];
NSLog(@"str1 retainCount == %d",[str1 retainCount]);
NSArray *arr= [[NSArray alloc]init];
NSLog(@" arrretainCount == %d",[arr retainCount]);
NSArray*arr1 = [[NSArray alloc]init];
NSLog(@"arr1 retainCount == %d",[arr1 retainCount]);
NSArray*arr2 = [[NSArray alloc]init];
NSLog(@"arr2 retainCount == %d",[arr2 retainCount]);
2
3
4
5...
你猜猜是多少
另外
把 NSArray
变成 NSString
你在试试看看另一个结果全是-1
关于NSarray 这个我可以解释通 但是-1何解?