IOS Retain,nil,alloc,init
retain----retainCount -1;
nil----retainCount =0;
1 Retain,alloc,init
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
SomeClass *object=[[SomeClass alloc] init];
NSLog(@"1,object retain count is :%d",[object retainCount]);
[object retain];
NSLog(@"2,object retain count is :%d",[object retainCount]);
object=nil;
//[object release];
NSLog(@"3,object retain count is :%d",[object retainCount]);
object=nil;
NSLog(@"4,object retain count is :%d",[object retainCount]);
[pool release];
return 0;
}
2 run result:
2012-07-15 00:49:52.122 RetainCounts[1259:f803] 1,object retain count is :1
2012-07-15 00:49:52.124 RetainCounts[1259:f803] 2,object retain count is :2
2012-07-15 00:49:52.125 RetainCounts[1259:f803] 3,object retain count is :0
2012-07-15 00:49:52.125 RetainCounts[1259:f803] 4,object retain count is :0