本帖最后由 yuanlingqi 于 2014-11-8 19:52 编辑
- //为何对retainCount为0的对象进行release却不会报野指针错误?详见下面代码
- #import "Person.h"
- #import "Car.h"
- @implementation Person
- -(void)setAge:(int)age{
- _age = age;
- }
- -(void)setCar:(Car*)car{
- if (car != _car) {
- [_car release];
- _car = [car retain];
- }
-
- }
- -(void)dealloc{
- [_car release];
- NSLog(@"年龄为%d的Person 被释放了。",_age);
- [super dealloc];
- }
- @end
复制代码
|
|