首页 > 解决方案 > 获得内存压力通知(关键/非关键) - iOS Objective-c

问题描述

收到内存压力通知(关键/非关键)。

在 tableview 中从 API 加载的“n”张图像。但是该应用程序在几秒钟后因上述错误而崩溃。当前的代码是,

[post_img sd_setImageWithURL:[NSURL URLWithString:[arr objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"placeHolder.jpg"] options:SDWebImageRefreshCached];

我试过删除缓存,

[[SDImageCache sharedImageCache] removeImageForKey:[arr objectAtIndex:i] fromDisk:YES withCompletion:nil];

另外,我尝试使用 dispatchqueue 获取图像,

dispatch_async(dispatch_get_global_queue(0,0), ^{
    NSData * data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: [arr objectAtIndex:i]]];
    if ( data == nil )
        return;
        dispatch_async(dispatch_get_main_queue(), ^{
            post_img.image = [UIImage imageWithData: data];
        });
    });

但我仍然得到错误。

标签: iosobjective-cimagesdwebimage

解决方案


推荐阅读