iOS基础学习

Objective-C基础学习之集合对象的内存管理

2017-10-26  本文已影响9人  WenJim

1.集合对象的内存管理

    NSMutableArray *arr = [[NSMutableArray alloc] init];

    Person *p = [[Person alloc] init];
    NSLog(@"retainCount = %lu", [p retainCount]);
    [arr addObject:p];
    NSLog(@"retainCount = %lu", [p retainCount]);
    [p release];
    NSLog(@"retainCount = %lu", [p retainCount]);
    [arr release];
    NSMutableArray *arr = [[NSMutableArray alloc] init];
    Person *p = [[Person alloc] init];
    NSLog(@"retainCount = %lu", [p retainCount]);
    [arr addObject:p];
    NSLog(@"retainCount = %lu", [p retainCount]);
    [arr removeObject:p];
    NSLog(@"retainCount = %lu", [p retainCount]);
    [p release];
    [arr release];

2.集合对象内存管理总结

上一篇 下一篇

猜你喜欢

热点阅读