OUT Of MEMORY Error, heap space, tri-dimensional array, graphics

Hello:

I am facing thisbizarre problem now.. ...

I have been translating an IDL code to Java and all have been, generally speaking,fine... until now that I defined a tri-dimensionaldouble array that has the following dimensions:

double[][][] rimage =newdouble[256][1738][26];

I will need, from now on, to continue working with tri-dimensional arrays for the final output that will be an image.

On the way to generate the image, my code will need to read another file, and so on.

I have tried following the steps on this page: http://hausheer.osola.com/docs/5to increase the heap size... I am not sure if I am making a mistake on the command or what, because I keep getting the " java.lang.OutOfMemoryError: Java heap space " . ..

This is what I am entering, to increase the heap:

java -Xms128m -Xmx512m

I am trying to increase the heap to 512mb to see if it gets solved.

Is there any way to force the Garbage Collector? What other steps do you suggest me to do to solve this? I really need to keep going!!

...I have already tried with System.gc();...

Oh,by the way,the code is inside a JSP.

Thanks!!

--mms-

[1338 byte] By [tofuwithcoffeea] at [2007-11-27 9:49:37]
# 1
How many of these arrays are you creating at once? That array will be about 88.25 MB, so if you have many of them, or other copies still in memory, you'll run out fast.
hunter9000a at 2007-7-13 0:18:11 > top of Java-index,Java Essentials,Java Programming...
# 2
Can't offer any help but you can't force the Garbage collector, you can call it but I don't think it makes much difference. The GC will always run before throwing an OutOfMemoryError.
_helloWorld_a at 2007-7-13 0:18:11 > top of Java-index,Java Essentials,Java Programming...
# 3
OMG.. I have many others!...Is there a way to delete an array permanently?Because, inside my code, I have some arrays that has many many items (more than 1000). I already used them, but will not use them anymore.--thanks!!--
tofuwithcoffeea at 2007-7-13 0:18:11 > top of Java-index,Java Essentials,Java Programming...
# 4

You can follow good practices such as declaring everything in the shortest scope and setting references to null where possible but it sounds like you have your work cut out. What exactly are you doing? it sounds like your are dealing with quite a lot of data here and maybe not the right hardware to support it.

This is what I get on my PC after increasing the memory size to 512

public static void main(String args[]){

double[][][] rimage = new double[256][1738][26];

System.out.println(Runtime.getRuntime().totalMemory() -

Runtime.getRuntime().freeMemory());

}

EDIT: Was using max memory instead of total!

_helloWorld_a at 2007-7-13 0:18:11 > top of Java-index,Java Essentials,Java Programming...
# 5
> Oh, by the way, the code is inside a JSP.That's neither here nor there. You must have added that just to make me throw up in my mouth a little.
BigDaddyLoveHandlesa at 2007-7-13 0:18:11 > top of Java-index,Java Essentials,Java Programming...
# 6
Hey BDLH's are you Hippolyte aka DrLazloJamf?
_helloWorld_a at 2007-7-13 0:18:11 > top of Java-index,Java Essentials,Java Programming...
# 7
> Hey BDLH's are you Hippolyte aka DrLazloJamf?[Laszlo]That's right. I'm too steatopygous for one moniker to cover me. And who'all are y'all?
BigDaddyLoveHandlesa at 2007-7-13 0:18:11 > top of Java-index,Java Essentials,Java Programming...
# 8
> > Hey BDLH's are you Hippolyte aka DrLazloJamf?> > [Laszlo]> > That's right. I'm too steatopygous for one moniker to> cover me. And who'all are y'all?An old lady with a rock bun. :-)
_helloWorld_a at 2007-7-13 0:18:11 > top of Java-index,Java Essentials,Java Programming...
# 9
> An old lady with a rock bun. :-)Aye, a guid tale's no the worse o bein twice told...
BigDaddyLoveHandlesa at 2007-7-13 0:18:11 > top of Java-index,Java Essentials,Java Programming...
# 10

> This is what I get on my PC after increasing the

> memory size to 512

> (...)

> EDIT: Was using max memory instead of total!

Ok, I added this to my code to see the output:double[][][] rimage;

_out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());

rimage = new double[(int)nangle][(int)nranges][(int)ncol];

...it gives the same error, without giving the output.

....If I include just....double[][][] rimage;

_out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());

//rimage = new double[(int)nangle][(int)nranges][(int)ncol];

...the output gives:

6,095,976

(6mb?)

If I keep refreshing the page, the values changes..

tofuwithcoffeea at 2007-7-13 0:18:11 > top of Java-index,Java Essentials,Java Programming...
# 11

Total memory is based on the current total memory in JVM, which can be a lot smaller than max memory which is the amount the heap will grow too before throwing an OutOfMemory error. In the seconds example with the bottom line commented out you are not using any memory. You are just declaring an array variable.

What are you actually doing? I.E what is the application. To think that something like this is living in a JSP is pretty scary, if you explain what exactly you are doing then people will be able to offer you more specific advice.

_helloWorld_a at 2007-7-13 0:18:12 > top of Java-index,Java Essentials,Java Programming...
# 12

>

> What are you actually doing? I.E what is the

> application. To think that something like this is

> living in a JSP is pretty scary, if you explain what

> exactly you are doing then people will be able to

> offer you more specific advice.

1. I have an ASCII file, which has more than 1500 values, and also I have a "raw data file" (unformatted data) which my code needs to read.

2. The Web based app. will read both files and format the "raw data" file. Then, it will use the data to generate an image.

3. The code will take the formatted data, that represents the "pixel colors" and where in the Graphic shall I "paint" those pixels.

--

... in one of the steps I am needed to save the formatted data in a tri-dimensional array... because these three values indicate the color and other information I need for the plotting....

--

Each unformatted file is about 25MB...

--

.....I'll reply later to any of your messages.... after another coffee break....

tofuwithcoffeea at 2007-7-13 0:18:12 > top of Java-index,Java Essentials,Java Programming...
# 13

Ok, I declared just this, in other JSP.. and it is also giving me the error:<%

PrintWriter _out = response.getWriter();

double[][][] rimage;

_out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());

rimage = new double[256][1738][26];

%>

... so if it is throwing that exception even for a single tridimensional array ... I will not be able to continue until I either get another machine to compile this, or try to see if I can do this without a tri-dimensional array...

....I already tried to increase the heap memory, to increase the virtual memory in my laptop... I'll see what else I can do..

Any help is appreciated.

tofuwithcoffeea at 2007-7-13 0:18:12 > top of Java-index,Java Essentials,Java Programming...
# 14

Ok... If I do something like:<%

PrintWriter _out = response.getWriter();

double[][] rimage;

double[] rimage2;

_out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());

rimage = new double[256][1738];

rimage2 = new double[26];

%>

...where I am NOT using a tri-dimensional array... it is not giving me any Out Of Memory exception...

Why is happening that?

For Java It is not the same?

tofuwithcoffeea at 2007-7-13 0:18:12 > top of Java-index,Java Essentials,Java Programming...
# 15

....and if I include this, inside the original code, it is flowing all normal... it seems that either my computer or I do not know what is not tolerating the tri-dimensional arrays...

//(...)

System.gc();

_out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());

_out.println("--");

double[][] rimage;

double[] rimage2;

rimage = new double[256][1738];

rimage2 = new double[26];

_out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());

The output gives me first "5567368" and then "9118160"

tofuwithcoffeea at 2007-7-21 23:10:27 > top of Java-index,Java Essentials,Java Programming...
# 16

okidoki...

The right command input was:java -Xmx512m

...not...java -Xmx 512m

...as I was entering....

...in addition I realize that my data could be defined as floats instead of doubles... so now I have a happy array of floats living in Happy Byte Land:int _nangle = (int)nangle;

int _nranges = (int)nranges;

int _ncol = (int)ncol;

float[][][] rimage = new float[_nangle][_nranges][_ncol];

tofuwithcoffeea at 2007-7-21 23:10:27 > top of Java-index,Java Essentials,Java Programming...