我试图在
Java中创建2D数组,如下所示:
int[][] adjecancy = new int[96295][96295];
但它失败了,出现以下错误:
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
解决这个问题的方法是增加JVM内存,但我正在尝试提交在线编码挑战的代码.它也失败了,我将无法改变那里的设置.
是否有任何标准限制或指导用于创建不应超过的大型阵列?
解决方法
int[][] adjecancy = new int[96295][96295];
当你这样做时,你试图分配96525 * 96525 * 32位,接近37091 MB,接近37演出.仅仅从Java获取内存是非常不可能的.
我认为你的程序初始化不需要那么多数据.可能你必须看看ArrayList,它给你动态的大小分配,然后在运行时继续释放是一个需要考虑的关键.
创建数组没有限制或限制.只要你有记忆,就可以使用它.但请记住,你不应该持有一块内存,这会让JVM变得忙碌.