Maximum limit for Java arrays

I tried to create a 2D array in Java, as follows:

int[][] adjecancy = new int[96295][96295];

But it failed with the following error:

JVMDUMP039I Processing dump event "systhrow",detail "java/lang/OutOfMemoryError" at 2017/04/07 11:58:55 - please wait.
JVMDUMP032I JVM requested System dump using 'C:\eclipse\workspaces\TryJavaProj\core.20170407.115855.7840.0001.dmp' in response to an event
JVMDUMP010I System dump written to C:\eclipse\workspaces\TryJavaProj\core.20170407.115855.7840.0001.dmp
JVMDUMP032I JVM requested Heap dump using 'C:\eclipse\workspaces\TryJavaProj\heapdump.20170407.115855.7840.0002.phd' in response to an event
JVMDUMP010I Heap dump written to C:\eclipse\workspaces\TryJavaProj\heapdump.20170407.115855.7840.0002.phd

The solution to this problem is to increase JVM memory, but I'm trying to submit code for the online coding challenge It also failed and I will not be able to change the settings there

Are there any standard restrictions or guidelines for creating large arrays that should not exceed?

Solution

int[][] adjecancy = new int[96295][96295];
int[][] adjecancy = new int[96295][96295];

When you do this, you try to allocate 96525 * 96525 * 32 bits, close to 37091 MB, close to 37 performances It's very impossible to just get memory from Java

I don't think your program needs so much data for initialization Maybe you have to look at ArrayList, which gives you dynamic size allocation, and then continues to release at runtime is a key consideration

There are no restrictions or restrictions on creating arrays As long as you have memory, you can use it But remember, you should not hold a piece of memory, which will make the JVM busy

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>