In my application I cache all images during startup in a Map
that looks somewhat like this:
Map<String, javafx.scene.image.Image> imageCache;
While profiling my application I noticed this map being the largest object in my application (~150MB). Which lead me to consider if it is at all necessary:
Images that are used as part of the user interface, do not need to be cached, as they are referenced from the UI.
Large images (1920x1920) may take a while until they are loaded and they usually need to be processed based on the window size before being displayed. These type of images are only used in one place (not referenced multiple times, not counting the cache), but over time they may be displayed multiple times (added and then removed from the scene graph).
In the future there will be small images that are used multiple times in the UI. Here it seems to make sense, to reuse the same Image
instance to reduce the memory footprint.
What is a good approach to this? Forgo caching altogether? Caching only specific images? If yes what should be the criteria?
I am aware that my description is a bit abstract, so if you want some clarification on certain points, please ask.