Out of Memory Error

X

Xiaolei Li

hi, got a weird out of memory error here that i can't figure out.
here's the code:

System.out.println("free: " + Runtime.getRuntime().freeMemory());
char[] big2 = new char[2034640181];
System.out.println("free: " + Runtime.getRuntime().freeMemory());

when i run that, i get:

[xli10@luna test]$ java -d64 -Xms6g -Xmx6g Test
free: 6379219712
Exception in thread "main" java.lang.OutOfMemoryError

so the VM has enough memory. top reports that i have 19G free. i also
ran the following code:

System.out.println("free: " + Runtime.getRuntime().freeMemory());
char[] big = new char[1034640181];
System.out.println("free: " + Runtime.getRuntime().freeMemory());
char[] big2 = new char[1034640181];
System.out.println("free: " + Runtime.getRuntime().freeMemory());

and i get:

[xli10@luna test]$ java -d64 -Xms6g -Xmx6g Test
free: 6379219712
free: 4309939168
free: 2240658784
[xli10@luna test]$

this completes successfully even though it needed more memory overall
than the first program. is there something tricky about allocating
large chunks of memory at one time? here's my java version info.

java version "1.4.2_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)

this is running on:

SunOS luna 5.8 Generic_117350-04 sun4u sparc SUNW,Sun-Fire-880

thank you very much.
 
B

Boudewijn Dijkstra

Xiaolei Li said:
hi, got a weird out of memory error here that i can't figure out.
here's the code:

System.out.println("free: " + Runtime.getRuntime().freeMemory());
char[] big2 = new char[2034640181];
System.out.println("free: " + Runtime.getRuntime().freeMemory());

when i run that, i get:

[xli10@luna test]$ java -d64 -Xms6g -Xmx6g Test
free: 6379219712
Exception in thread "main" java.lang.OutOfMemoryError

It could very well be that the VM is refusing to allocate >=2GB arrays.
What's wrong with using 1941 times a 2MB array, anyway?
[SNIP]

this completes successfully even though it needed more memory overall
than the first program. is there something tricky about allocating
large chunks of memory at one time? here's my java version info.

java version "1.4.2_05"
Java(TM) 2 Runtime Environment, Standard Edition (build
1.4.2_05-b04)
Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)

this is running on:

SunOS luna 5.8 Generic_117350-04 sun4u sparc SUNW,Sun-Fire-880
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top