autoreleasepool
当你在循环内创造大量的临时变量的时候,可以使用 autoreleasepool ,降低内存的峰值.
for (int i = 0; i < 1000000000; i++) {
// @autoreleasepool {
NSString *str = [NSString stringWithFormat:@"hello -%04d", i];
str = [str stringByAppendingString:@" - world"];
NSLog(@"str == %@",str);
// }
}
这个循环里的大佬使用了 临时变量,所占的内存会不断的上升
加上 autoreleasepool 内存会稳定