Suggestions needed for decreasing memory usage
Iím new around here though I do have some experience with Java. I signed up because Iím hoping I can get some recommendations and suggestions for the smart way to solve a problem I have with a hobby project :)
Some explanation is needed. My program is used for administering a map campaign, played in real time. The map is divided into a number of provinces, each owned by a team. The participating players are divided into the teams. I think a picture will help explain the concept:
Here the provinces are marked with borders in the colour of their owning team. The players are marked with flags in the colour of their team. The borders are laid out in a way so that if two provinces share a border, a player can travel between them.
Now the idea of the campaign is that players move between provinces and when they meet up with a player of another team, a battle ensues. If the attacking player wins this battle, he can capture the province for his team. Since itís real time the player icons move slowly across the map as time passes.
Now for the Java part of it. The program has already been used for the first time but I had to cut some corners to get it done since I was a bit short on time. For now my problem is mostly a memory issue. Each province has an image for each team colour. With 5 teams and 27 provinces itís 135 images (at about 16 Kb each itís about 2.2 Mb), each loaded as a BufferedImage. Besides that there are the map image (160 Kb), 24 player icons (less than 1 Kb each) and a few extra small icons.
When I loaded all of it I started getting memory heap errors, which I so far have solved with giving the desktop application extra memory (the -Xmx512m option).
Right, Iím finally getting to where I need some help. Iíd like to find a better way to solve this memory issue if possible. One reason is to improve the desktop application, since it takes a short while to repaint every province; another reason is that Iím working on a way to display the map as playback on a website and initially Iím thinking using an applet since I can reuse a lot of my current classes. The trouble is itís not feasible to increase the memory available in an applet as far as I know.
Options Iím considering:
2) Donít load every single province image but only those needed at the time being, and load a new image when a province changes owner. But Iím not sure if thatíll be enough.
3) Make the desktop application save an image each time a province change owner. Since the provinces donít change owners that often, the applet would have a smaller amount of images to load, as it wouldnít have to load any specific province images. Each image would be larger, though.
4) A better way to do it?
Can anyone help?
(oh, and please ask if some of it doesnít make sense :))