黑马程序员技术交流社区

标题: objective -c 引用 [打印本页]

作者: 路默”    时间: 2014-4-29 23:25
标题: objective -c 引用
#import <Foundation/Foundation.h>

@interface testClass: NSObject

@property(nonatomic, retain)NSArray* a;

@end

@implementation  testClass

@synthesize a;

@end

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

{

    NSArray* t;testClass *c;

    @autoreleasepool {

t  = [[NSArray alloc]init];

    NSLog(@"%d", [t retainCount]);

c = [testClass alloc];

    c.a = t;

    NSLog(@"%d", [t retainCount]);

    NSLog(@"%d", [c.a retainCount]);

[t release];

NSLog(@"%d", [t retainCount]);

    NSLog(@"%d", [c.a retainCount]);

}

    NSLog(@"%d", [t retainCount]);

    NSLog(@"%d", [c.a retainCount]);

    return 0;

}

不明白为什么输出:
2014-04-29 22:58:08.220 tttt[2064:303] 2

2014-04-29 22:58:08.222 tttt[2064:303] 3

2014-04-29 22:58:08.224 tttt[2064:303] 3

2014-04-29 22:58:08.225 tttt[2064:303] 2

2014-04-29 22:58:08.227 tttt[2064:303] 2

2014-04-29 22:58:08.232 tttt[2064:303] 2

2014-04-29 22:58:08.233 tttt[2064:303] 2





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2