So here is the code
and here is the result:
Why do the first 4 objects have a retain count of 2?
TIA
Edit: I just found out that some NSNumbers are cached.
Code:
int main (int argc, const char * argv[]) {
NSNumber* newNumber;
int i;
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
for (i = 0; i < 40; i++) {
newNumber = [[NSNumber alloc] initWithInt:(i * 3)];
NSLog(@"%d\n", [newNumber retainCount]);
}
[pool drain];
return 0;
}
and here is the result:
Code:
2008-05-18 00:51:11.287 Lottery[845:10b] 2
2008-05-18 00:51:11.289 Lottery[845:10b] 2
2008-05-18 00:51:11.290 Lottery[845:10b] 2
2008-05-18 00:51:11.290 Lottery[845:10b] 2
2008-05-18 00:51:11.291 Lottery[845:10b] 2
2008-05-18 00:51:11.291 Lottery[845:10b] 1
2008-05-18 00:51:11.291 Lottery[845:10b] 1
2008-05-18 00:51:11.292 Lottery[845:10b] 1
2008-05-18 00:51:11.292 Lottery[845:10b] 1
...
Why do the first 4 objects have a retain count of 2?
TIA
Edit: I just found out that some NSNumbers are cached.