Have a look at this code-snippet with a simple retain/release scenario:
#import <Foundation/Foundation.h>
@interface SomeClass : NSObject
@end
@implementation SomeClass
@end
int main(int argc, const char * argv[])
{
SomeClass *aClass = [[SomeClass alloc] init];
NSLog(@"retainCount: %lu", [aClass retainCount]);
[aClass retain];
NSLog(@"retainCount: %lu", [aClass retainCount]);
[aClass release];
NSLog(@"retainCount: %lu", [aClass retainCount]);
[aClass release];
NSLog(@"retainCount: %lu", [aClass retainCount]);
return 0;
}
That's the resulting output:
2013-04-29 17:33:50.695 retainCount: 1
2013-04-29 17:33:50.697 retainCount: 2
2013-04-29 17:33:50.697 retainCount: 1
2013-04-29 17:33:50.698 retainCount: 1
The last retainCount should either be "0" or the app should crash. Why is the result "1" ?!