playframework - IOException unable to allocate mem

2020-02-28 05:59发布

问题:

My system is Mint 12 64bit.

I've installed the typesafe stack and created a new play application. Without modifying the code I've tried to run it. This is the output:

http://pastebin.com/6XwmsbAE

Play complains with this error message:

IOException: Cannot run program "javac": java.io.IOException: error=12, Cannot allocate memory 

How can I fix this ?

UPDATE:

@Mef

Ok you were definitely right. I've increased the initial RAM from 1 GB to 2 GB (running this on virtualbox). Compiling worked exactly once.

Unfortunately java has made up his mind that even 2 GB aren't enough: Running eclipse and firefox my system uses 1 GB. Then I start sbt and the memory usage rises to about 1.2 GB. One might think that this is sufficient. It isn't. Compilation fails with the same error although 800 MB are still available. Moreover after trying to compile the application the memory usage goes up to 1.6 GB. Strangely enough even while compiling the project it never reaches 2 GB but peaks at about 1.8 GB.

Nevertheless I've tried again and fed 3 gigs of RAM to the virtual machine. Now compiling and running the application works fine. As another miracle with 3 GB available the memory usage never rises above 1.6 GB and stays well below the maximum of 1.8 GB that I saw in the 2 GB iteration.

回答1:

Since this is a general javac error, I doubt that it is Play related. Most likely you really ran out of memory.



回答2:

Actually this is not entirely a system error: tweaking the play config files will allow you to make it work on a system with less than 1GB of memory.

In play-2.0.4/framework/build (or build.bat), you just need to change

java ${DEBUG_PARAM} -Xms512M -Xmx1536M ...

to

java ${DEBUG_PARAM} -Xms128M -Xmx512M ...

Now there can be other issues running play with less memory, but at least the basic setup works.



回答3:

This is very well described in another post and it seems to be a problem with OpenJDK.

How to solve "java.io.IOException: error=12, Cannot allocate memory" calling Runtime#exec()?

Try the following:

# echo 1 > /proc/sys/vm/overcommit_memory

This has worked for me :-)