本帖最后由 洪吉童 于 2015-10-14 22:24 编辑
- //***********Person.h **************/
- #import <Foundation/Foundation.h>
- @class Car;
- @interface Person : NSObject
- @property (nonatomic,retain) Car *car;
- @end
- /**************person.m*********************/
- #import "Person.h"
- #import "Car.h"
- @implementation Person
- -(void)dealloc
- {
- [car release];
- NSLog(@"Person对象被回收");
- [super dealloc];
- }
- @end
- /************************Car.h************************/
- #import <Foundation/Foundation.h>
- @class Person;
- @interface Car: NSObject
- @property (nonatomic,retain)Person *person;
- @end
- /**************Car.m*********************/
- #import "Car.h"
- @implementation Car
- -(void)dealloc{
复制代码- [person release];
- NSLog(@"car对象被回收");
- [super dealloc];
- }
- @end
- /********main.****************/
- #import <Foundation/Foundation.h>
- #import "Car.h"
- #import "Person.h"
- int main(int argc, const char * argv[]) {
-
- Person *p = [[Person alloc]init];
- Car *c = [[Car alloc] init];
- p.car = c ;
- c.person = p;
- [c release];//这一句执行完不是应该执行c的临终遗言dealloc吗?怎么直接执行下面的[p release]了?
- [p release];
- return 0;
- }
复制代码 上面的最后几行代码中[c release];,不是应该执行c的临终遗言dealloc吗?怎么直接执行下面的[p release]了?
|
|