循环retain


#import 
#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 
@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 
@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

你可能感兴趣的:(循环retain)