Reputation: 24318
Can anyone help, i have some code and i am checking the retainCount but its always -1, it should be 1 at least?
here is my code, what am i doing wrong?
NSNumber* n = [[NSNumber alloc] initWithInt:100];
NSLog(@"Count of n : %i",[n retainCount]);
NSNumber* n1 = n;
NSLog(@"Count of n : %i",[n retainCount]);
NSLog(@"Count of n1: %i",[n1 retainCount]);
NSLog(@"Address of n : %p", n);
NSLog(@"Address of n1: %p", n1);
The other strange thing i get is regarding the %i, saying that it actually returns a uint, so i replaced the %i to a %u and now i get a really long figure for the retainCount - 4294967295
A little confused, any ideas?
Thanks in advance
Upvotes: 1
Views: 143
Reputation: 104698
The result of -retainCount
is worthless at your abstraction level, and this is another reason why.
…but to get on with your question: NSUIntegerMax
indicates an immortal object.
You can find references to this in some documentation:
You might override this method in a class to implement your own reference-counting scheme. For objects that never get released (that is, their release method does nothing), this method should return UINT_MAX, as defined in
<limits.h>
.
Upvotes: 11