onevcat / Kingfisher

A lightweight, pure-Swift library for downloading and caching images from the web.
MIT License
23.4k stars 2.66k forks source link

KFImage(_ url: URL?) huge heap memory #1668

Open MoveUpwardsDev opened 3 years ago

MoveUpwardsDev commented 3 years ago

Check List

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

Issue Description

Doing a simple load remote image in a SwiftUI view increase application memory usage

What

I use KFImage to load 28 remote PNG images about 200Ko each. Before loading images, application is around 50 Mo memory usage. After loading images and show screen, the application memory usage is 130 Mo.

I have check with Instruments and seen images turns from 200 ko to several Mo

I have tried another library named url-image to achieve the same and application memory stays as it should from 50 Mo to 52 Mo.

Reproduce

KFImage(url: url) .resizable() .aspectRatio(contentMode: .fit)

Other Comment

Here is the same images to reproduce

https://gps.algo.tibtop-connect.com/images/xgy6LHiVq4Tg.png https://gps.algo.tibtop-connect.com/images/oWNudpAZ4xFR.png https://gps.algo.tibtop-connect.com/images/N_RyqHqWHIUx.png https://gps.algo.tibtop-connect.com/images/62j7WezmaxPs.png https://gps.algo.tibtop-connect.com/images/8HEPDEwvOBBk.png https://gps.algo.tibtop-connect.com/images/mhkUXPXZUWgr.png https://gps.algo.tibtop-connect.com/images/JANAP7nxCv35.png https://gps.algo.tibtop-connect.com/images/-anrraFQR56F.png https://gps.algo.tibtop-connect.com/images/ntSlzD6zGzYA.png https://gps.algo.tibtop-connect.com/images/8iEsm3vWvhzA.png https://gps.algo.tibtop-connect.com/images/Gc3JsStKX62D.png https://gps.algo.tibtop-connect.com/images/_HEv5fuNKf4J.png https://gps.algo.tibtop-connect.com/images/5Dfkg4Qcaq0Y.png https://gps.algo.tibtop-connect.com/images/5vSjhNSxQX27.png https://gps.algo.tibtop-connect.com/images/L1ZyiEfYmwtm.png https://gps.algo.tibtop-connect.com/images/47J3T2sr_fJa.png https://gps.algo.tibtop-connect.com/images/rE4w0wNZCfR6.png https://gps.algo.tibtop-connect.com/images/87czV1yKnaf7.png https://gps.algo.tibtop-connect.com/images/LKGI0EzFwhnj.png https://gps.algo.tibtop-connect.com/images/3t1lTB7GbkEz.png https://gps.algo.tibtop-connect.com/images/THwsZD5jeb0g.png https://gps.algo.tibtop-connect.com/images/KkwQmjrtZJhh.png https://gps.algo.tibtop-connect.com/images/iLqlIfgOeiwl.png https://gps.algo.tibtop-connect.com/images/Co_cqSwaIMHR.png

markst commented 1 month ago

Related https://github.com/onevcat/Kingfisher/issues/1718 ?

markst commented 1 month ago

I guess it's by design that the images are stored in RAM and only cleared upon memory warning:

https://github.com/onevcat/Kingfisher/wiki/New-In-Kingfisher-5#aggressive-strategy-by-default

https://github.com/onevcat/Kingfisher/blob/4a2333d471e6aa671cbea6ed0c884eac4d90d6fb/Sources/Cache/ImageCache.swift#L205