Kingfisher icon indicating copy to clipboard operation
Kingfisher copied to clipboard

ImageDownloader with .backgroundDecode produces CG Raster Data Leak

Open crousselle2 opened this issue 6 years ago • 3 comments

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

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: Screen Shot 2019-05-08 at 12 33 51 PM

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 deinit is called
  • The Raster Data will leak and stay present in the overall allocations.

crousselle2 avatar May 08 '19 10:05 crousselle2

I guess it is not what Kingfisher could control.

Maybe it worths to confirm it on a device instead of a simulator.

onevcat avatar May 09 '19 14:05 onevcat

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

crousselle2 avatar May 09 '19 15:05 crousselle2