摘要: // // Person.h #import @interface Person : NSObject @property (nonatomic, assign) int age; + (instancetype)person; - (instancetype)initWithAge:(int)age; + (instancetype)personWithAge:(int)age... 阅读全文
posted @ 2017-08-25 17:27 无天666 阅读(212) 评论(0) 推荐(0)
摘要: // // main.m // autorelease注意事项 #import #import "Person.h" int main(int argc, const char * argv[]) { Person *p1 = [[Person alloc] init]; @autoreleasepool { Person *p2 = [[[... 阅读全文
posted @ 2017-08-25 17:07 无天666 阅读(224) 评论(0) 推荐(0)
摘要: // // main.m /* autorelease也是用于内存管理的,给对象发送autorelease消息就会把对象放入autoreleasepool这个池子中,当池子销毁的时候会对池子里面的所有对象发送一条release消息,只是计数器减一,不一定会销毁。 1.autorelease方法会返回对象本身,好比init方法, Person *p = [Person new]; ... 阅读全文
posted @ 2017-08-25 16:37 无天666 阅读(255) 评论(0) 推荐(0)
摘要: // main.m // 循环retain #import #import "Person.h" #import "Dog.h" int main(int argc, const char * argv[]) { Person *p = [Person new]; Dog *d = [Dog new]; // 如果A对用要拥有B对象, 而B对应又要拥... 阅读全文
posted @ 2017-08-25 15:49 无天666 阅读(200) 评论(0) 推荐(0)
摘要: // // main.m #import #import "Person.h" int main(int argc, const char * argv[]) { Person *p = [Person new]; Dog *d = [Dog new]; p.dog = d; [p release]; [d release];... 阅读全文
posted @ 2017-08-25 15:29 无天666 阅读(149) 评论(0) 推荐(0)
摘要: // Person.h #import @class Car; //#import "Car.h" // 由于import是一个预编译指令, 他会将""中的文件拷贝到import所在的位置。 // 并且import有一个特点, 只要""中的文件发生了变化, 那么import就会重新拷贝一次(更新操作)。 // @class仅仅是告诉编译器, @class后面的名称是一个类, 不会做任何拷... 阅读全文
posted @ 2017-08-25 15:15 无天666 阅读(250) 评论(0) 推荐(0)
摘要: // // main.m // 多个对象内存管理练习 // // ARC是Xcode帮我们生成内存释放的代码,MRC是需要我买自己写retain和release。想研究内存管理只能在MRC,管理对象就是在管理引用计数器,计数器为0对象就释放。 // 给空指针发消息不会报错,给野指针发消息就会报错。 // 对象与对象之间有关系时候就用retain。 #import #import "... 阅读全文
posted @ 2017-08-25 14:55 无天666 阅读(256) 评论(0) 推荐(0)
摘要: // // Person.h #import #import "Room.h" #import "Car.h" #import "Dog.h" @interface Person : NSObject { Room *_room; Car *_car; Dog *_dog; } /* - (void)setRoom:(Room *)room; - (void)se... 阅读全文
posted @ 2017-08-25 14:18 无天666 阅读(208) 评论(0) 推荐(0)
摘要: // // main.m // Set方法的内存管理 #import #import "Person.h" #import "Room.h" int main(int argc, const char * argv[]) { @autoreleasepool { // 1.创建两个对象 Person *p = [[Person allo... 阅读全文
posted @ 2017-08-25 11:15 无天666 阅读(198) 评论(0) 推荐(0)