Sanjay Salunkhe Sanjay Salunkhe - 27 days ago 11
Java Question

jruby rails : Java::JavaLang::OutOfMemoryError: Java heap space

I am trying to compile my javascript assets. i have included plotly.js file which is almost 2MB in size. also i have included angualr2.dev.js file which is again 1MB in size.

whenever i am compiling my assets using command

rake assets:precompile RAILS_ENV=production
i am getting below error.

Java::JavaLang::OutOfMemoryError: Java heap space
org.mozilla.javascript.NativeArray.<init>(org/mozilla/javascript/NativeArray.jav
a:66)
org.mozilla.javascript.Context.newArray(org/mozilla/javascript/Context.java:1626
)
org.mozilla.javascript.ScriptRuntime.newArrayLiteral(org/mozilla/javascript/Scri
ptRuntime.java:3733)
org.mozilla.javascript.Interpreter.interpretLoop(org/mozilla/javascript/Interpre
ter.java:1776)
org.mozilla.javascript.Interpreter.interpret(org/mozilla/javascript/Interpreter.
java:815)
org.mozilla.javascript.InterpretedFunction.call(org/mozilla/javascript/Interpret
edFunction.java:109)
org.mozilla.javascript.NativeArray.iterativeMethod(org/mozilla/javascript/Native
Array.java:1635)
org.mozilla.javascript.NativeArray.execIdCall(org/mozilla/javascript/NativeArray
.java:330)
org.mozilla.javascript.IdFunctionObject.call(org/mozilla/javascript/IdFunctionOb
ject.java:97)
org.mozilla.javascript.Interpreter.interpretLoop(org/mozilla/javascript/Interpre
ter.java:1479)
org.mozilla.javascript.Interpreter.interpret(org/mozilla/javascript/Interpreter.
java:815)
org.mozilla.javascript.InterpretedFunction.call(org/mozilla/javascript/Interpret
edFunction.java:109)
org.mozilla.javascript.NativeArray.iterativeMethod(org/mozilla/javascript/Native
Array.java:1635)
org.mozilla.javascript.NativeArray.execIdCall(org/mozilla/javascript/NativeArray
.java:330)
org.mozilla.javascript.IdFunctionObject.call(org/mozilla/javascript/IdFunctionOb
ject.java:97)
org.mozilla.javascript.Interpreter.interpretLoop(org/mozilla/javascript/Interpre
ter.java:1479)
org.mozilla.javascript.Interpreter.interpret(org/mozilla/javascript/Interpreter.
java:815)
org.mozilla.javascript.InterpretedFunction.call(org/mozilla/javascript/Interpret
edFunction.java:109)
org.mozilla.javascript.NativeArray.iterativeMethod(org/mozilla/javascript/Native
Array.java:1635)
org.mozilla.javascript.NativeArray.execIdCall(org/mozilla/javascript/NativeArray
.java:330)
org.mozilla.javascript.IdFunctionObject.call(org/mozilla/javascript/IdFunctionOb
ject.java:97)
org.mozilla.javascript.Interpreter.interpretLoop(org/mozilla/javascript/Interpre
ter.java:1479)
org.mozilla.javascript.Interpreter.interpret(org/mozilla/javascript/Interpreter.
java:815)
org.mozilla.javascript.InterpretedFunction.call(org/mozilla/javascript/Interpret
edFunction.java:109)
org.mozilla.javascript.NativeArray.iterativeMethod(org/mozilla/javascript/Native
Array.java:1635)
org.mozilla.javascript.NativeArray.execIdCall(org/mozilla/javascript/NativeArray
.java:330)
org.mozilla.javascript.IdFunctionObject.call(org/mozilla/javascript/IdFunctionOb
ject.java:97)
org.mozilla.javascript.Interpreter.interpretLoop(org/mozilla/javascript/Interpre
ter.java:1479)
org.mozilla.javascript.Interpreter.interpret(org/mozilla/javascript/Interpreter.
java:815)
org.mozilla.javascript.InterpretedFunction.call(org/mozilla/javascript/Interpret
edFunction.java:109)
org.mozilla.javascript.NativeArray.iterativeMethod(org/mozilla/javascript/Native
Array.java:1635)
org.mozilla.javascript.NativeArray.execIdCall(org/mozilla/javascript/NativeArray
.java:330)
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)


How i can resolve this issue ??

Answer

try pre-compiling using an alternate ExecJS runtime (e.g. having node installed)

... instead of gem 'therubyrhino'

Comments