- #import <Foundation/Foundation.h>
- #import "Person.h"
- //验证内存管理的原则:谁retain,谁release
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
- Person *p = [Person new];
- NSLog(@"retainCount = %ld",[p retainCount]);
- Person *p1 = [p retain];
- NSLog(@"retainCount = %ld",[p retainCount]);
- [p1 release];
- NSLog(@"retainCount = %ld",[p retainCount]);
- [p release];
- }
- return 0;
- }
复制代码
按照内存管理的原则中有:谁retain,谁release,可上面的代码中,用p release仍然可以,请问该如何理解? |
|