续:
OC之内存管理值ARC机制:
#import <Foundation/Foundation.h> #import "Person.h" #import "Car.h" int main(int argc, const char * argv[]) { @autoreleasepool {
Person *fengjie = [Person new]; Car *bmw = [Car new]; // 1 bmw.speed = 280; //给凤姐一辆车 [fengjie setCar:bmw]; // 2 //区拉萨 [fengjie goLasa];
// bmw 1, person dealloc 1-->0 // fengjie _car bwm
[fengjie goLasa]; [fengjie goLasa]; [fengjie goLasa];
//创建另外一辆车 Car *byd = [Car new]; // 1 byd.speed = 80; [fengjie setCar:byd]; // 2 byd //_car = byd [fengjie goLasa];
// byd 2--->1 [fengjie goLasa];
} return 0; }
|