• Register
0 votes
260 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 105 views
105 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 189 views
189 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 90 views
90 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
0 votes
1 answer 8 views
8 views
How can I solve this?
asked Dec 28, 2020 TeamScript 10.3k points
0 votes
1 answer 2.2K views
2.2K views
Problem : I am getting below error while running my Jersey API in Tomcat 8.5.11 java.lang.illegalstateexception: injectionmanagerfactory not found.
asked Nov 1, 2019 peterlaw 6.9k points
0 votes
1 answer 142 views
142 views
Problem : I am new to Servlet programing, while running my Servlet code i am getting bellow error error 500 javax servlet servletexception java lang illegalstateexception
asked Oct 23, 2019 peterlaw 6.9k points
0 votes
1 answer 315 views
315 views
Problem : I am getting bellow error when I start my locale instance of Tomcat the exception was: java.net.bindexception: cannot assign requested address: bind
asked Oct 19, 2019 peterlaw 6.9k points
0 votes
1 answer 152 views
152 views
Problem : When I installed the final certificate I got the following error: keytool error: java.lang.Exception: Failed to establish chain from reply
asked Oct 23, 2019 peterlaw 6.9k points
0 votes
1 answer 375 views
375 views
Problem : I am getting bellow error while using Sockets java.net.socketexception: software caused connection abort: socket write error
asked Oct 19, 2019 peterlaw 6.9k points
0 votes
1 answer 1.4K views
1.4K views
Problem : I have already placed the JSTL JAR file in the WEB-INF/lib directory. But still, the JSP can't resolve the taglib. I get the below error: Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
asked Oct 19, 2019 peterlaw 6.9k points