title: Caching Image in JavaFX application?
body: <p>In my application I cache all images during startup in a <code>Map</code> that looks somewhat like this:</p>
  
  <pre><code>Map&lt;String, javafx.scene.image.Image&gt; imageCache;
  </code></pre>
  
  <p>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:</p>
  
  <p>Images that are used as part of the user interface, do not need to be cached, as they are referenced from the UI.</p>
  
  <p>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).</p>
  
  <p>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 <code>Image</code> instance to reduce the memory footprint.</p>
  
  <p>What is a good approach to this? Forgo caching altogether? Caching only specific images? If yes what should be the criteria?</p>
  
  <p>I am aware that my description is a bit abstract, so if you want some clarification on certain points, please ask.</p>