- Person *p1 = [[Person alloc] init];
- Person *p2 = [[Person alloc] init];
- Person *p3 = [[Person alloc] init];
-
- [p1 release];
- [p2 release];
- [p3 release];
- 2014-06-27 20:37:19.058 小小测试[2828:303] 对象被回收了
- 2014-06-27 20:37:19.061 小小测试[2828:303] 对象被回收了
- 2014-06-27 20:37:19.063 小小测试[2828:303] 对象被回收了
复制代码
有alloc 有release 内存无泄漏
- Person *p1 = [[Person alloc] init];
- Person *p2 = [[Person alloc] init];
- Person *p3 = [[Person alloc] init];
-
- NSArray *array = [NSArray
- arrayWithObjects:p1, p2, p3, nil];
-
- [p1 release];
- [p2 release];
- [p3 release];
- 这样就没有调用dealloc方法
复制代码
除非这样
- Person *p1 = [[Person alloc] init];
- Person *p2 = [[Person alloc] init];
- Person *p3 = [[Person alloc] init];
- @autoreleasepool {
-
- NSArray *array = [NSArray arrayWithObjects:p1, p2, p3, nil];
-
- }
- [p1 release];
- [p2 release];
- [p3 release];
复制代码
我的疑问是,如果不用@autorelease{} 怎么手动管理内存 |
|