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