I am setting an image to UITableViewCell
from AlamofireImage with the extension af_setImageWithURL
that's work perfectly when I scroll it too fast the memory size is increased and it does not decrease however I stop the scrolling.
I am using in UITableViewCell
class:
imgProduct.image = UIImage()
clearImageFromCache(imageURL)
let filter = AspectScaledToFillSizeFilter(size: imgProduct.frame.size)
imgProduct.af_setImageWithURL(imageURL, placeholderImage: UIImage(),filter: filter)
I have also tried NSURLCache.sharedURLCache().removeAllCachedResponses()
but no luck.
func clearImageFromCache(URL:NSURL) {
let URLRequest = NSURLRequest(URL: URL)
let imageDownloader = UIImageView.af_sharedImageDownloader
// Clear the URLRequest from the in-memory cache
imageDownloader.imageCache?.removeImageForRequest(URLRequest, withAdditionalIdentifier: nil)
// Clear the URLRequest from the on-disk cache
imageDownloader.sessionManager.session.configuration.URLCache?.removeCachedResponseForRequest(URLRequest)
}
Here is the screenshot of memory debugging:
Before:
After scrolling:
NOTE:- It works perfectly when I scroll without images.
Try to deallocate the image
imgProduct.image = nil