Open vvvladvvvolkovvvskiy opened 1 year ago
Created own UIImage not from generated kotlin object. Clear don't work, cache depends on lifecycle app
Hello! In which case did you encounter this problem? When using Compose / UIKit / both? Can you share reproducer project? It would be very helpful in understanding the problem and finding solution.
Using SwiftUI.
For example :
App contains 30 images
App navigation : Screen1 -> Screen2 -> Screen3. (my case, struct Screen[1,2,3] : View
)
Each screen have horizontal pager with unique images(Screen1 contains from 0 to 10 images, Screen2 from 10 to 20, ...)
Use Image(uiImage : Res.shared.images.customImage)
While navigate between pages image load, cached and increase memory
At Screen3, previous screens decomposed, but memory not cleared and contains previously images
Found that
UIImage(named:) caches images, and UIImage(contentsOfFile:) does not.
And when lifecycle goes to background cache of images cleared.
To check ram, used XCode -> Debug Navigator -> Memory -> Memory use
Okay, I see.
As a possible solution, I can add object url
containing URLs to images, so then image can be created using
UIImage(contentsOfFile: Res.shared.image.url.customImage)
Or a new object assets
(as part of future raw file functionality), then
UIImage(contentsOfFile: Res.shared.asset.image.customImage)
I prefer the second option as the first one can break backwards compatibility (if project has an image called url
).
I'll think about it.
Thanks for help
UIImage.imageNamed cached. When use a lot of images, cache eating a lot of ram
Apple says : If you intend to display an image only once and don't want it added to the system’s cache, create it using the [imageWithContentsOfFile:]
Ideal have option, that indicate reusage images Don't know how fix.
Sorry, i'm android developer and don't have a lot of expirience to help with ios