我正在玩objective-c并进行了样本测试。在非弧环境中,我有以下代码:
NSNumber * one;
NSLog(@"At first one retain count is: %d",[one retainCount]);
one = [[NSNumber alloc]initWithInt:5];
NSNumber * two = [[NSNumber alloc]initWithInt:1];
NSNumber * three =[[NSNumber alloc]initWithInt:2];
NSLog(@"After initializing %d",[one retainCount]);
NSMutableArray * array = [NSMutableArray arrayWithObjects:one,two,three, nil];
NSLog(@"After adding to array it is: %d",[one retainCount]);
NSString * a = [array objectAtIndex:0];
NSLog(@"Assigning to variable a: %d",[one retainCount]);
NSLog(@" %@ ",a);
[one release];
[array removeObjectAtIndex:0];
NSLog(@"after releasing and removing from array %d",[one retainCount]);
NSLog(@" %@ ",a);
似乎我无法使用 nslog 变量 a 但我可以做到。我得到以下输出;
2013-03-07 17:57:09.706 采访[33491:11303] 首先保留计数为:3
2013-03-07 17:57:09.707 采访[33491:11303] 初始化后 2
2013-03-07 17: 57:09.707 采访[33491:11303] 添加到数组后为:3
2013-03-07 17:57:09.707 采访[33491:11303] 分配给变量 a:3
2013-03-07 17:57:09.707 采访[33491:11303] 5
2013-03-07 17:57:09.707 采访[33491:11303] 释放并从阵列 1 中删除后
2013-03-07 17:57:09.708 采访[33491:11303] 5
即使我应该解除变量 a ,我怎么可能仍然使用它?