Results 1 to 2 of 2
  1. #1
    TheEnemy is offline Member
    Join Date
    Feb 2011
    Rep Power

    Default 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:

    1) Donít use an applet and instead show the map on the website using JavaScript

    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 :))

  2. #2
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Rep Power


    Here are some options:

    - reduce the image buffer sizes. You can do this by reducing the width and height, or if you're currently using an int color map, you can switch to an IndexColorModel based on bytes instead of int's ( a 4x reduction in memory usage).

    - cache to disk anything that is not needed nor expected to be needed soon

    - don't use an applet.

    - have your applet change the default heap sizeif necessary. If your applet is going to do it, it'll have to be a signed applet and you'll have to put code in for all the operating systems you plan to support since they are all different.

    - walk the user through changing the default heap size for the java plugin.

    Sun Java Plugin - How to Increase the Java Applet Memory Limit

    - complain to Oracle that there should be an API for changing the heap size programmatically

Similar Threads

  1. Memory usage
    By Moon_E in forum New To Java
    Replies: 20
    Last Post: 07-09-2010, 10:53 PM
  2. heap memory usage anomaly?
    By jon80 in forum Threads and Synchronization
    Replies: 1
    Last Post: 06-30-2009, 06:56 AM
  3. Replies: 2
    Last Post: 12-07-2008, 07:13 PM
  4. JVM memory usage
    By lardum in forum New To Java
    Replies: 7
    Last Post: 06-26-2008, 03:30 AM
  5. Latest XML parsing and memory usage benchmark
    By Jimmy Zhang in forum XML
    Replies: 0
    Last Post: 03-03-2008, 10:49 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts