请问:“把对象捕获到 block 中,然后扔到后台队列去随便发送个消息以避免编译器警告,就可以让对象在后台线程销毁了。”我写了个demo,为啥不生效呢?作者的原意是什么呀?
}
(void)t93_destory {NSArray *arr11 = @[@"aaa", @"bbb", @"ccc"];NSArray *tmp = arr11;arr11 = nil;NSLog(@"111__%@_%@", arr11, tmp);dispatch_async(dispatch_queue_create("kqykqy", DISPATCH_QUEUE_CONCURRENT), ^{
NSLog(@"222 _%@_%@_%@",[NSThread currentThread], arr11, tmp); [tmp class]; NSLog(@"333 tmp_%@_%@_%@",[NSThread currentThread], arr11, tmp);
});
sleep(2);NSLog(@"444_%@_%@_%@",[NSThread currentThread], arr11, tmp);
1、测试方式不对2、作者的原意是指: “当容器类持有大量对象时,其销毁时的资源消耗就非常明显,可以通过一个小 Tip:把对象捕获到 block 中,然后扔到后台队列去随便发送个消息以避免编译器警告,就可以让对象在后台线程销毁了 ”
看关键字:前提:持有大量对象时,个人理解:对象比较多或是占用资源比较大时原因:销毁时的资源消耗就非常明显,个人理解: CPU 占用太多,影响性能啦目的:避免编译器警告
持有大量对象时
销毁时的资源消耗就非常明显
避免编译器警告
2.1m questions
2.1m answers
60 comments
56.6k users