Code:
#import <Foundation/Foundation.h>
@interface Person : NSObject
@end
@implementation Person
- (void)dealloc {
NSLog(@"Person-dealloc");
[super dealloc];
}
@end
int main(int argc, const char * argv[]) {
// 创建自动释放池的两种方式-方式1
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
// 实例对象被置于释放池中
Person* p1 = [[[Person alloc] init] autorelease];
[pool release];
// 创建自动释放池的两种方式-方式2
@autoreleasepool {
// 实例对象被置于释放池中
Person* p2 = [[[Person alloc] init] autorelease];
}
return 0;
}
Output:
Person-dealloc
Person-dealloc