Reputation: 23
I'm trying to sort a list of 1 billion integers using Collection.sort(List) and it throws following exception "Exception in thread "main" java.lang.OutOfMemoryError: Java heap space" -xms is set as 512m and xmx at 1536m. How do i sort it? I've 8GB ram in my system so allocating more physical memory is not a problem. I tried giving -xmx 2048m but vm could not initialize with that setting.
Upvotes: 0
Views: 529
Reputation: 12398
I tried giving -xmx 2048m but vm could not initialize with that setting.
You are likely using a 32-bit JVM, which have a practical max heap size below 2GB. You should try a 64-bit JVM.
Note also that you should set the VM parameters for the program, not for Eclipse (as it seems you are doing per one of your comments). You do that by selecting the dropdown menu in Run then Run Configurations. Then select your program and open the Arguments panel.
Upvotes: 1
Reputation: 19821
It's likely case-sensitive and there should be no space, try with -Xmx2048m
.
Nonstandard Options
-Xmxn
Specifies the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2 MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is chosen at runtime based on system configuration.
For server deployments, -Xms and -Xmx are often set to the same value. See Garbage Collector Ergonomics at http://docs.oracle.com/javase/7/docs/technotes/guides/vm/gc-ergonomics.html
Examples:
-Xmx83886080
-Xmx81920k
-Xmx80m
See docs.
Upvotes: 2