-1

I am trying the following code

String[] buffer = new String[1447891223];
Arrays.fill(buffer, "0.0");

The above code gives me java.lang.OutOfMemoryError: Java heap space

Is there any way i could do the above way optimally?

MY sts.ini file have the following configuration

-startup
plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.300.v20150602-1417
-product
org.springsource.sts.ide
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
512M
-vmargs
-Dosgi.requiredJavaVersion=1.7
-Xms1024m
-XX:MaxPermSize=512m
-Xverify:none
-Dorg.eclipse.swt.browser.IEVersion=10001
-Xmx4000m
Pri_stack
  • 179
  • 1
  • 12

2 Answers2

0

Well, do you really need that many String objects? You will have to use at least ~6GB of memory to have pointers to ~1.5 billion strings. Maybe you wanted a String of 1.5 billion characters? That would be a bit less, but not much.

Also, you will have to provide JVM parameters like -Xmx to increase the size of available memory by JVM

0

You should be able to initialize the array of size 1447891223 with minimum -Xms9g memory. Set one of your VM args as -Xms9g or -Xmx9g

import java.util.Arrays;

public class BigArray {

    public static void main(String[] args) {
        String[] buffer = new String[1447891223];
        Arrays.fill(buffer, "0.0");
    }
}

QuickSilver
  • 3,915
  • 2
  • 13
  • 29