Skip to main content

Lowering Memory Usage

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2011-04-25

Okay guys, I'm trying to make a simple animation program, so I have these this in my code to hold the data for what has been "painted" to each frame

// Holds the artwork, max of 1000 frames, and 10,000 possible cells for each frame
static public cell cells[][] = new cell[1000][10000];

// The cell class
static public class cell {
public short x;
public short y;
public byte value;

public cell(short xVal, short yVal, byte val) {
x = xVal;
y = yVal;
value = val;

Right now, when I run the built JAR, the Task Manager says I'm using 76,244KBs, witch roughly equates to a usage of 74.45MBs. I have 2GB of Ram, but I realy don't like the number of MBs in use.

Any tips?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2006-11-23

Well, it's all in the big numbers. You're talking about a possible 10 million cells here. Considering that a short is 16 bits and a byte is 8 bits, you're using up to 24 bits per Cell, excluding any address space for the references, classes and any other things Java likes to store. 24 bits * 10M = 240M bits. Divide that by 8, you end up using 30 MB for cells alone. Also, don't forget that your array needs to store 10 million references to each cell, which can add up very quickly too. I know from first hand that this simple mathematics is flawed in many ways (If someone has a better way of predicting memory usage, I would really like to know!), so I would advise you to use a profiler for this. (*shameless plug* I use JProfiler, which is awesome in many ways)