Autorelease实际上只是把对release的调用延迟了,对于每一个Autorelease,系统只是把该Object放入了当前的Autorelease pool中,当该pool被释放时,该pool中的所有Object会被调用Release
for (int i = 0; i <= 1000; i ++) {
//创建一个自动释放池
NSAutoreleasePool *pool = [NSAutoreleasePool new];//也可以使用
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"PNG"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:filePath];
UIImage *image2 = [image imageByScalingAndCroppingForSize:CGSizeMake(480, 320)];
[image release];
//将自动释放池内存释放,它会同时释放掉上面代码中产生的临时变量image2
[pool drain];
}