Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Industries Academia Support User Community Company

Technical Solutions

How do I increase the heap space for the Java VM in MATLAB 6.0 (R12) and later versions?


Date Last Modified: 28 Jul 2008
Solution ID:   1-18I2C
Product:   MATLAB
Reported in Release:   R12
Platform:   All Platforms
Operating System:   All OS
 

Subject:

How do I increase the heap space for the Java VM in MATLAB 6.0 (R12) and later versions?

Problem Description:

I would like to increase the Java VM heap space in MATLAB 6.0 (R12) and later versions.

Solution:

As of MATLAB 6.0 (R12), you can increase the heap space for the Java Virtual machine (VM) as follows:

1. Create a file in the $MATLABROOT/bin/$ARCH directory (or in the MATLAB startup directory). The file name should be


java.opts
Note: $MATLABROOT is the MATLAB root directory and $ARCH is your system architecture.
You can find the MATLAB root directory on your machine, by typing at the MATLAB Command Prompt:
matlabroot

You can find the system architecture by executing the following at the MATLAB Command Prompt:
computer('arch')

To create a java.opts file, you just need to create a text file and name it as java.opts.


NOTE: If you are performing these operations in MATLAB 7.5 (R2007b), you may want to read the bug report located at:

http://www.mathworks.com/support/bugreports/details.html?rp=398525

2. The contents of the java.opts file consist of the following lines of text:
For the JVM versions 1.2 and up:

-Xmx268435456
For the 1.1.8 JVM:

maxHeapSize = 268435456
This will give you 256MB of JVM memory and you can adjust the parameter as needed.

For the 1.3 and 1.2 JVM, our defaults are:

-Xms16000000
-Xmx64000000
For the 1.1.8 JVM (Windows, Linux, Solaris, Alpha, SGI) our defaults are:
 
minHeapSize = 16000000
maxHeapSize = 64000000
These are the structure field names in <jni.h> that correspond to -ms and -mx, and the settings above are roughly 16MB and 64MB.

To determine the version of Java you are running, type the following at the MATLAB command prompt:
version -java
You can use the following commands to obtain information about the Java heap::
java.lang.Runtime.getRuntime.maxMemory
java.lang.Runtime.getRuntime.totalMemory
java.lang.Runtime.getRuntime.freeMemory
When the free memory hits zero, Java will double the heap size (up to the maximum setting).

In some cases, increasing the Java stack size above a certain limit can cause Java memory problems. See the Related Solution listed below for more information.

http://www.mathworks.com/support/bugreports/details.html?rp=398525

  Provide feedback to help us improve this solution!
Contact support
Print this page