I have enable the ARC. but this code makes me wonder
@interface Dog : NSObject
@end
@implementation Dog
- (void)dealloc
{
printf("Dog is dealloc\n"); //the function not called
}
@end
@interface Person : NSObject
@property (nonatomic, strong) Dog *dog;
@end
@implementation Person
- (void)dealloc
{
printf("Person is dealloc\n");
_dog = nil;
}
-(Dog *)dog
{
return _dog;
}
@end
int main()
{
Person *p = [[Person alloc] init];
p.dog = [[Dog alloc]init];
Dog* d = p.dog;
d=nil;
p=nil;
printf("end\n");
return 0;
}
the result is
Person is dealloc
end
Program ended with exit code: 0
why the dog's dealloc method not called. and then I commented out this Method, the dog's dealloc method called.
//-(Dog *)dog
//{
// return _dog;
//}
thank you very much.
