内存管理

 retain----retainCount -1;

   nil----retainCount =0;

 

 1 Retain,alloc,init

int main(int argc, char *argv[])

{

    NSAutoreleasePool *pool=[[NSAutoreleasePool allocinit];

    

    SomeClass *object=[[SomeClass allocinit];

    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

 

 

 

 
posted @ 2012-11-09 14:03  xiaoxiaoxigua  阅读(120)  评论(0编辑  收藏  举报