Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
At the time I started using Mathematica it lived happily within the 4MB constraints of my computer... –  Sjoerd C. de Vries Jul 3 '13 at 13:25
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. –  Leonid Shifrin Jul 3 '13 at 15:21
add comment

2 Answers

up vote 9 down vote accepted

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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