Java caps memory

问题: When I try to initialize a big array: double [][][] test = new double[500][1000][1000]; There comes the error: Exception in thread "main" java.lang.OutOfMemoryError:...

问题:

When I try to initialize a big array:

double [][][] test = new double[500][1000][1000];

There comes the error:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at tests.Test.main(Test.java:6)

When I give arguments to java:

-Xmx2048m

There comes the error:

Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap

and the text is black.


Task manager says

Physical Memory: 44%

and from my computer I have these stats:

Windows 7 Ultimate

Processor: Intel(R) 'Core(TM) i5-3470 CPU @ 3.20GHz

Installed memory (RAM): 8,00 GB (7,89 GB usable)

System type: 64-bit Operating System


回答1:

A double is 8 bytes. Your array is 500 * 1000 * 1000 * 8 which is roughly 3.8 GB.

You need to allocate a bigger heap to accommodate this array, try -Xmx5g to allow some additional memory for the rest of your application.

  • 发表于 2019-01-06 22:21
  • 阅读 ( 210 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除