dispatch_async(dispatch_get_global_queue(0, 0), ^{
for(NSInteger i = 0; i < NSIntegerMax; i++) {
NSString *str = [NSString stringWithFormat:@"hello - %ld", i]; //加入autoreleasepool会导致内存飙升
//RootViewController * vc = [[RootViewController alloc] init]; //不会造成内存升高,超过作用域内存回收
}
});
上面代码执行后内存飙升,app会崩溃,使用@autoreleasepool 包一下就好了。
dispatch_async(dispatch_get_global_queue(0, 0), ^{
for(NSInteger i = 0; i < NSIntegerMax; i++) {
@autoreleasepool {
NSString *str = [NSString stringWithFormat:@"hello - %ld", i];
}
//RootViewController * vc = [[RootViewController alloc] init];
}
});