zoukankan      html  css  js  c++  java
  • iOS 图片加载导致内存警告

    虽然UITableView和UICollectionView都有cell复用机制,但是如果利用SDWebImage加载的图片本身过大且cell复用池中的个数比较多(cell的Size越小,复用池中的cell就越多),

    就容易收到内存溢出的警告!控制台会打印:Received memory warning.

    解决办法:
    在 didReceiveMemoryWarning方法中释放SDImage的缓存即可!
    Objective-C:
    - (void)didReceiveMemoryWarning {
        [superdidReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
        [[SDWebImageManagersharedManager] cancelAll];
        [[SDImageCachesharedImageCache] clearDisk];
    }


    如果加载的是项目本地的大图导致的内存溢出,解决办法如下:
    建议使用该方法获取图片 - 但是不会自动匹配@2x @3x等
    NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"xds" ofType:@"png"];
    UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagePath];
     
    而不要使用下面的方法,图片过大容易造成内存溢出
    UIImage *image = [UIImage imageNamed:@"xds.png"];

  • 相关阅读:
    C# 泛型
    EventHandler<TEventArgs>委托
    只能输入数字 ,只能有一位小数点。
    MVC过滤器 AuthorizeAttribute使用
    NuGet EntityFramework 常用命令
    Stride游戏引擎试毒
    Unity EditorWindow GUI裁剪
    unity2017自定义编译dll
    Unity
    WPF
  • 原文地址:https://www.cnblogs.com/yujidewu/p/5685431.html
Copyright © 2011-2022 走看看