Using the same image several times: does it eat up more RAM?
Hello there :)
I have a question about how images loaded with java.awt.Image are managed internally.
Here's what I'm doing:
I'm writing a Swing component that will be used several times at once because it will appear inside a child window in a MDI setup. And this component loads a PNG image from the disk to draw it as a background.
And I'm not sure how to go with that...
Because if I load that image from the constructor and keep the reference it might load one image in the memory for each window and thus eat up a lot of RAM. Unless Java takes care of making sure that images are loaded only once, but I'm not sure it does so I hoped you could tell me.
The other way I'm considering is to have a ResourceManager singleton class that takes care of loading all the images that my program will need, and store them in a HashMap so they can be picked up anywhere in the code using a string identifier.
What would be the best design?