從服務器上下載一些gzipped xml文件,將其保存到文檔文件夾並解壓縮每個文件。之後,我刪除.gz文件。我在一個循環中做了或多或少的500個文件。在使用儀器時,我發現在這個過程之後,實際字節或多或少是470MB。當Im等待幾秒鐘時,ARC清除它並且應用程序將達到5MB活動字節。但是因爲它的同步過程,我的應用程序在下載和解壓縮之後不會停止,所以我的應用程序會立即收到內存警告。至少我認爲應該可以強制ARC釋放內存?或者我有一個真正的錯誤代碼,我仍然沒有看到?使用ARC下載並解壓文件後的內存警告
任何幫助或暗示真的很感激。
下載並解壓縮:
for(NSString *filePath in filePaths){
NSString *localPath = [[DownloadManager sharedInstance] downloadFile:filePath];
if(localPath){
//downloaded correctly
if([self unzipFileAtPath:localPath]){
[FileUtility deleteFileAtPath:localPath];
}
}
}
解壓方法:
+ (BOOL)unzipFileAtPath:(NSString *)path
{
NSData *gzData = [NSData dataWithContentsOfFile:path];
NSData *ungzippedData = [gzData gunzippedData];
BOOL success = [ungzippedData writeToFile:[FormatUtility pathWithoutGz:path] atomically:NO];
ungzippedData = nil;
gzData = nil;
return success;
}
我會稍後嘗試,並給你一個反饋。聽起來不錯,可能是我搜索的東西,謝謝! – NDY
這是解決方案!非常感謝。 – NDY
@達倫是否也是這樣的解決方案? http://stackoverflow.com/questions/19159932/memory-warning-while-downloading-file-with-afhttprequestoperation – Burak