Main.m
#import "Person.h"
#import "Dog.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
Person *person = [[Person alloc] init]; //person:1
Dog *dog = [[Dog alloc] init]; //dog:1
[person setDog:dog]; //dog:1
[dog setPerson:person]; //person:2
[person release]; //person:1
[dog release]; //dog:0
NSLog(@"test");
}
return 0;
}
Person.h
@class Dog;
@interface Person : NSObject
@property(nonatomic, assign)Dog *dog;
Person.m
#import "Dog.h"
@implementation Person
- (void)dealloc
{
NSLog(@"person销毁了");
// [_dog release];
[super dealloc];
}
Dog.h
@class Person;
@interface Dog : NSObject
@property(nonatomic, retain)Person *person;
Dog.m
#import "Person.h"
@implementation Dog
- (void)dealloc
{
NSLog(@"dog销毁了");
[_person release];
[super dealloc];
}