ImageDownloader with .backgroundDecode produces CG Raster Data Leak
Check List
Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.
- [x] I have read the wiki page and cheat sheet, but there is no information I need.
- [x] I have searched in existing issues, but did not find a same one.
- [x] I want to report a problem instead of asking a question. It'd better to use kingfisher tag in Stack Overflow to ask a question.
Issue Description
I am using the default ImageDownloader to retrieve images from our servers. Pretty standard implementation:
ImageDownloader.default.downloadImage(with: url, options: [.backgroundDecode]) { [weak self] result in
var image: UIImage?
switch result {
case let .success(value): image = value.image
default:
break
// Pass my image in completion block
}
The image is downloaded correctly and I'm able to display it without any issues. However, upon profiling my issue, I notice a huge memory consumption.
What
There seem to be CG Raster Data to be leaked during the background decoding (at least that's what Instruments suggests)
Here is an Instrument Screenshot:

Reproduce
- Set a UIViewController with an image to be displayed (in my case it's a collection view, so, several images) (our URL are simple S3 download URLs that I cannot provide)
- the download call can simply be in
viewDidLoad() - Push this view controller onto a UINavigationController
- Image(s) will be downloaded and displayed correctly
- Raster Data will be visible on Instrument
- Pop that view controller and make sure
deinitis called - The Raster Data will leak and stay present in the overall allocations.
I guess it is not what Kingfisher could control.
Maybe it worths to confirm it on a device instead of a simulator.
I will test that, I however tested that removing .backgroundDecode from the options removed the leak, which is what led me to believe it was on the framework's side