#import "Gun.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
Person *ren=[Person new];
ren.name=@"士兵";
NSLog(@"ren===%lu",ren.retainCount);
Gun *p=[Gun new];
NSLog(@"p===%lu",p.retainCount);
p.name=@"玫瑰精灵";
ren.rose=p;
[p retain];
NSLog(@"p===%lu",p.retainCount);
[ren shoot];
ren.rose=p;
[ren shoot];
Gun *p2=[Gun new];
p2.name=@"黑骑士";
//
ren.rose=p2;
[p2 retain];
[ren shoot];
[ren release];
[p release];
[p2 release];
// NSLog(@"ren===%lu",ren.retainCount);
// NSLog(@"p===%lu",p.retainCount);
// NSLog(@"p2===%lu",p2.retainCount);
}
return 0;
} |
|