Just wanted to get a handle on a preferred way of handling images. In my game I currently have 8 different backgrounds I use at various stages during my game, at the moment I currently create a cache of the 8 images (752x512 JPG ~ 150KB) at start up. But I am beginning to think, convinced by profiling, that I am eating up unnecessarily large amounts of ram - Some of the images aren't going to be used (should I use lazy-loading perhaps?).

So my question is, should I switch to loading the image when I require it in the game? Thus only having 1 buffered image at anyone time for the background? A pause in the game whilst it loads the image, for the level, is fine. I am just thinking - with this method I am going to incur more GC's due to rotation of different backgrounds.

Whichever floats your boat. Getting back 7x150KB isn't going to make a difference but if you strive for least memory usage, go for it. If you want the best user experience, those extra 1.05MB aren't going to hurt

Usually when you start looking at these kind of optimizations you'll never stop and the game will linger instead of being finished ;-)

Personally I'd consider (if it is a small scale applet/webstart game) to stream the new pictures from the server the first time they are needed, that'll decrease the initial loading time with something like 10-20 seconds for people with "normal" connections.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org