NSNumber*n1=[[NSNumberalloc]initWithInt:10];NSNumber*n2=[[NSNumberalloc]initWithInt:100];NSLog(@"retain count of n1 is %i",[n1retainCount]);NSLog(@"retain count of n2 is %i",[n2retainCount]);
NSNumber*n1=[[NSNumberalloc]initWithInt:10];NSLog(@"retain count of n1 is %i",[n1retainCount]);NSNumber*n2=[[NSNumberalloc]initWithInt:100];NSLog(@"retain count of n2 is %i",[n2retainCount]);NSNumber*n3=[[NSNumberalloc]initWithInt:100];NSLog(@"retain count of n3 is %i",[n3retainCount]);NSNumber*n4=[[NSNumberalloc]initWithInt:10];NSLog(@"retain count of n4 is %i",[n4retainCount]);
結果是:
retain count of n1 is 2
retain count of n2 is 1
retain count of n3 is 1
retain count of n4 is 3
又試著把他們的位址印出來:
12345
// address of numsNSLog(@"address of n1 is %p",n1);NSLog(@"address of n2 is %p",n2);NSLog(@"address of n3 is %p",n3);NSLog(@"address of n4 is %p",n4);
結果是:
address of n1 is 0x100108e20
address of n2 is 0x10010cb30
address of n3 is 0x10010cb50
address of n4 is 0x100108e20