问题5:将图像保存到模型的优缺点

优点:不用重复下载,利用MVC刷新表格,不会造成数据混乱,加载速度比较快

缺点:内存,所有下载好的图像 都会记录在模型里,如果数据比较多

造成内存警告

//在真实开发中,一定要注意这个方法

-(void) didReceiveMemoryWarning{

 [super didReceiveMemoryWarning];

//需要在这里作一些内存清理的工作 ,如果不处理,会被系统强制闪退

}

在模型中定义图片属性,图像和模型耦合性太强,导致清理内存困难

解决办法:

将图片保存在控制器中

@property (nonatomic,strong) NSMutableDictionary *imageCache;

-(NSMutableDictionary *) imageCache{

   if(_imageCache == nil){

      _imageCache = [NSMutableDictionary dictionary];

    }

    return  _imageCache;

}

 

原文地址:https://www.cnblogs.com/seeworld/p/5905800.html