循环retain

2016-01-09  本文已影响45人  MarkTang

#import <Foundation/Foundation.h>
#import "Person.h"
#import "Dog.h"
int main(int argc, const char * argv[]) {
    @autoreleasepool {
        Person *p = [[[Person alloc]init]autorelease];
        Dog *d = [[[Dog alloc]init]autorelease];
        p.dog = d;
        d.person = p;
    }
    return 0;
}
#import <Foundation/Foundation.h>
@class Dog;
@interface Person : NSObject
@property(nonatomic,retain)Dog *dog;
@end
#import "Person.h"
#import "Dog.h"
@implementation Person
- (void)dealloc
{
    self.dog = nil;
    
    NSLog(@"%s",__func__);
    [super dealloc];
}
@end
#import <Foundation/Foundation.h>
@class Person;
@interface Dog : NSObject
@property(nonatomic,assign)Person * person;
@end
#import "Dog.h"
#import "Person.h"
@implementation Dog
- (void)dealloc
{
//    self.person = nil;
    NSLog(@"%s",__func__);
    [super dealloc];
}
@end
上一篇下一篇

猜你喜欢

热点阅读