zoukankan      html  css  js  c++  java
  • iOS App占用太多磁盘空间

    问题:随着App的不断运行,发现所占磁盘空间越来越大

    分析:应该是网络下载中的缓存,包括利用SDWebImage产生的、和下载单个文件被取消后的缓存

    验证:查看App目录中的Tmp(系统存放未下载完成的文件的缓存的地方),cache(SDWebImage 存放缓存的地方)

    如上图,下载文件缓存有374M;如下图,SDWebImageCache有20M

    最后附上检测文件大小的方法

    - (float ) folderSizeAtPath:(NSString*) folderPath{
        NSFileManager* manager = [NSFileManager defaultManager];
        if (![manager fileExistsAtPath:folderPath]) return 0;
        NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
        NSString* fileName;
        long long folderSize = 0;
        while ((fileName = [childFilesEnumerator nextObject]) != nil){        
            NSString* fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
            folderSize += [self fileSizeAtPath:fileAbsolutePath];
        }
        return folderSize/(1024.0*1024.0);
    }
    
    - (NSString *)TmpPathDirectory {
        return NSTemporaryDirectory();
    }
    
    - (NSString *)cachePathDirectory {
        NSArray*paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES);
        NSString *path = [paths objectAtIndex:0];
        return path;
    }
  • 相关阅读:
    常用正则表达式
    玉洁哥的设计模式指摘
    jquery makearray()使用
    html/css技巧总结
    json 数组 对象 xml 之间转换(待补充)
    Html5 Geolocation获取地理位置信息
    JSON.stringify 应用
    url操作一网打尽(一)
    jquery选择器
    JavaScript Window Location
  • 原文地址:https://www.cnblogs.com/Apple2U/p/5670410.html
Copyright © 2011-2022 走看看