如何释放(未使用的)内存?

作为亚马逊ec2的新手,我正在努力使我的申请工作。 我通过SSH连接了几次,我一直在运行和停止服务器,有时连接丢失,还有一些其他的东西…

在某些时候,我从JVM(我的应用程序使用Scala)得到的错误是没有足够的可用内存,并且无法分配它来运行自己。 我所做的是重新启动服务器。 有效。 但我认为应该有更有效的方法。 有没有?

更新

Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5550000, 715849728, 0) failed; error='Cannot allocate memory' (errno=12) # # There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (malloc) failed to allocate 715849728 bytes for committing reserved memory. # An error report file with more information is saved as: # /home/ubuntu/my-app/hs_err_pid8668.log 

我会看看两个变化:

  • 我很确定你需要调整你的JVM的内存使用情况(启动-Xmx )来匹配你所在的机器。 确保你没有要求比你的虚拟机有更多的内存。
  • 放弃你的overcommit设置。 来自Re:invent 2013的演讲build议overcommit_memory=2overcommit_ratio=80 。 用overcommit进入一个不好的地方会导致malloc失败,就像你看到的一样。