我使用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