I have noticed that Mathematica makes use of Java by way of JLink, for example, in the extensions such as DatabaseLink and (I think) RLink. It also seems like Java is a first-class citizen for writing our own extensions.

An issue that I almost always run in to is that my data sets are too large for the default Java heap size (-Xmx). Almost all of my notebooks have ReinstallJava at the top, where the maximum Java memory is set to some large fraction of the 256 gigabytes of RAM in my computer. On computers of this size, the default Java setting seems like the 640K memory limit (who could need more than that?)

Sometimes, it seems hard to figure out how to set the Java memory for certain packages (e.g. in RLink, apologies, this could be made into a separate question for that.)

My question: is there a place where I can "hard-wire" the maximum Java memory for a given computer so that I don't need the boiler plate code?

  • 1
    $\begingroup$ At the time I started using Mathematica it lived happily within the 4MB constraints of my computer... $\endgroup$ Commented Jul 3, 2013 at 13:25
  • 3
    $\begingroup$ For Rlink, there is an option "JRELocation" for InstallR[]. You can use it not just to specify the location of your JRE, but also to enter command-line parameters, in particular those that govern the memory usage limits for JVM. $\endgroup$ Commented Jul 3, 2013 at 15:21

2 Answers 2


Along the lines of Yamareth's answer, but probably an even better technique, is to put the following into $UserBaseDirectory/Kernel/init.m:

SetOptions[InstallJava, JVMArguments->"-Xmx32g"]
SetOptions[ReinstallJava, JVMArguments->"-Xmx32g"]

By setting the default options, you will get the desired heap size any time you (or any other code you run) calls ReinstallJava in your session.


Place your call to ReinstallJava in init.m file found in $UserBaseDirectory/Kernel.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.