Autorelease實(shí)際上只是把對release的調(diào)用延遲了上遥,對于每一個Autorelease刽肠,系統(tǒng)只是把該Object放入了當(dāng)前的Autorelease pool中溃肪,當(dāng)該pool被釋放時,該pool中的所有Object會被調(diào)用Release
for (int i = 0; i <= 1000; i ++) {
//創(chuàng)建一個自動釋放池
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];
//將自動釋放池內(nèi)存釋放音五,它會同時釋放掉上面代碼中產(chǎn)生的臨時變量image2
[pool drain];
}