// Person复合了Phone和Room
// 第一种
- (void)setPhone:(Phone *)phone
{
if (phone != _phone)
{
[_phone release];
_phone = [phone retain];
}
}
// 第二种
- (void)setRoom:(Room *)room
{
[room retain];
[_room release];
_room = room;
}
- (void)dealloc
{
NSLog(@"%s", __func__);
self.phone = nil; // 赋值为nil会调用setter完成下面的两步操作
// 等效的
[_room release];
_room = nil;
[super dealloc];
}
原文:http://www.cnblogs.com/pruple/p/5240198.html