OutOfMemoryError: Java heap space when running jruby on rails console but not using all the memory defined by -J-Xmx

StackOverflow https://stackoverflow.com/questions/14877146

Question

I have a rails 3 app using jruby 1.7 and I'm trying to use the rails console on my local dev environment (OS X 10.8 with jdk 7) in a situation that would require a lot of memory. I run the rails console as following:

jruby -J-Xms1024m -J-Xmx4096m -J-XX:+UseConcMarkSweepGC -J-XX:+CMSIncrementalMode -S rails c samuel_hml

Then I start a long running process using the rails console/

The jruby java process always fails after raising an "OutOfMemoryError: Java heap space" error. But when I run the console and check the Activity Monitor, it never actually uses more then 700 mb.

Was it helpful?

Solution

I found the solution:

RAILS_ENV=samuel_hml jruby -J-Xms1024m -J-Xmx4096m -J-XX:+UseConcMarkSweepGC -J-XX:+CMSIncrementalMode -S rails c

jruby was ignoring my "-J-Xms1024m -J-Xmx4096m -J-XX:+UseConcMarkSweepGC -J-XX:+CMSIncrementalMode" parameters

OTHER TIPS

Do you have some kind of wrapper arround your java? Normally it is -Xmx

jruby -Xms1024m -Xmx4096m -XX:+UseConcMarkSweepGC -J-XX:+CMSIncrementalMode -S rails c samuel_hml

It is just a guess but I had similar problems when I worked with java native buffers. I set 2048MB of maximum heap size and got OutOfMemoryError even though the monitor showed me that not all the memory was used. The real problem was not with java memory but with native memory that actually run out. I checked it out with system monitor.

My problem was resolved when I decreased the amount of memory for java giving more free space for native buffers.

So maybe here you have something alike ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top