我使用alamofire框架从服务器下载图像。我与Alamofire.download合作。每张图片的大小都超过1MB + - ,但每次请求后内存都会增加很多。下载4张图像后,使用的内存高于171MB,之后每幅图像的大小超过35MB。 下载代码:Alamofire .dowload需要大量内存(ios,swift)
Alamofire.download(mainReguest, to: self.destination)
.downloadProgress{ progress in
self.progressView.progress = Float(progress.fractionCompleted)
}
.response{ response in
if response.error == nil, let imagePath = response.destinationURL?.path {
let image = UIImage(contentsOfFile: imagePath)
self.addNewImageToTheScrollView(img: image)
}
}
}
代码的目的地是:
let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory,
in: .userDomainMask,
with: [DownloadRequest.DownloadOptions.removePreviousFile])
https://stackoverflow.com/questions/38889134/swift-download-image-from-internet-and-cache-them-doesnt-work-properly-need-s/38890731#38890731 –
尝试此链接并让我知道你是否有任何困惑..! –
下载图片的尺寸是多少? – user3581248