自动释放池

来源:互联网 发布:知乎段子手 编辑:程序博客网 时间:2024/05/21 21:59

    //创建

    NSAutoreleasePool *pool = [[NSAutoreleasePoolalloc]init];

    

    Dog *d1 = [[Dogalloc]init];

    Dog *d2 = [d1retain];

    Dog *d3 = [d1retain];

    NSLog(@"%ld",d1.retainCount);

    

    [d1 autorelease];//d1指向的对象加入自动释放池

    [d2 autorelease];

    [d3 autorelease];

    

    //释放

    [pool release];


    

    @autoreleasepool {

        Dog *d4 = [[Dogalloc]init];

        [d4 autorelease];   

    }


0 0