• Register
0 votes
419 views

Problem :

I am getting bellow memory error
java.lang.outofmemoryerror requested array size exceeds vm limit
6 5 3
6,930 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

I doubt you may be using sorts on a large index. 

That is one thing I know can require a large array size with Lucene. 

You might want to try using a 64-bit JVM with these options:

-Xmx6G -XX:MaxPermSize=128M -XX:+UseCompressedOops

The last option will reduce 64-bit memory pointers to 32-bit This typically reduces the memory overhead by about 40%, so it can help stretch your memory significantly.

This will solve your memory related issue.

9 7 4
38,600 points
0 votes

Java has got a limit on the maximum array size your program can allocate. The exact limit is platform-specific but is generally between the somewhere 1 and 2.1 billion elements.

What is the reason?

This error is thrown by the native code within the JVM. This happens before allocating the memory for an array when the JVM performs platform-specific tasks, whether the allocated data structure is addressable in this platform.

  • Your array grows too big and ends up having the size between the platform limit and the integer Max_LIMIT.
  • You try to allocate the arrays larger than 2^31-1 elements to experiment with this limit.

Example:

When trying to recreate the java.lang.OutOfMemoryError: Requested array size exceeds VM limit error. Let's look at the following code;

for (int i = 3; i >= 0; i--) {

            try {

                        int[] arr = new int[Integer.MAX_VALUE-i];

                        System.out.format("Successfully initialized an array with %,d elements.\n", Integer.MAX_VALUE-i);

            } catch (Throwable t) {

                        t.printStackTrace();

            }

}

The example iterates four times and initializes an array of long primitives on each turn. In this program, the size of an array is trying to initialize grows by one with every iteration and finally reaches Integer Max value.

Solution:

Initialize the array size with integer MAX_VALUE-2 to get rid of such errors;

int [] arr = new int[Integer.MAX_VALUE-2];

 

11 5 2
3,890 points

Related questions

0 votes
1 answer 5 views
5 views
Problem: I want to do performance testing of large files using java in Amazon cloud. Help me someone.
asked May 3 salim1 60.6k points
1 vote
1 answer 11 views
11 views
Problem: How can I get rid of this error? Error:java.lang.outofmemoryerror: gc overhead limit exceeded.
asked Apr 28 PkGuy 23.5k points
0 votes
1 answer 132 views
132 views
Problem : I am getting bellow error while I execute my JUnit tests exception in thread "main" java.lang.outofmemoryerror: gc overhead limit exceeded
asked Oct 19, 2019 peterlaw 6.9k points
0 votes
1 answer 205 views
205 views
Problem : I am getting bellow minecraft error minecraft error: java.lang.outofmemoryerror: gc overhead limit exceeded
asked Oct 23, 2019 peterlaw 6.9k points
1 vote
1 answer 178 views
178 views
Problem : I am very new to Java Programming also I have very recently started using the Intellij as the IDE. I have observed that If I try to use it then sometimes it is delayed a lot. I have tried changing my xms and xmx for the larger heap size (i.e. xms ... the maximum heap size". Because of above error message I have already rolled back my changes. Please let me know how can I fix above error?
asked May 9, 2020 stewart 4k points
1 vote
1 answer 6 views
6 views
Problem: I am getting this error : java.lang.OutOfMemoryError: GC overhead limit exceededHow can I solve this and what does it means?
asked May 5 Raj Tyagi 15.6k points
0 votes
1 answer 5 views
5 views
Problem: What caused the error, " error: java.lang.outofmemoryerror: gc overhead limit exceeded " ?
asked Apr 12 salim1 60.6k points
1 vote
1 answer 6 views
6 views
Problem: How to fix this error : java.lang.outofmemoryerror: gc overhead limit exceeded
asked Mar 25 MUHAMMAD MUNEEB 83k points
0 votes
1 answer 12 views
12 views
How can I solve this?
asked Dec 28, 2020 TeamScript 13.5k points
1 vote
1 answer 5 views
5 views
Problem: I am getting an error which is given bwlow please help me: Could not publish to the server. java.lang.nullpointerexception.
asked May 1 PkGuy 23.5k points