I would like to investigate the Java Virtual Machine (JVM) memory profile as my MATLAB code is executing.
It is possible to monitor the memory usage of the JVM by using JConsole. Additionally there are some 3rd party tools, such as JMP, which provide more features. With either option, you must use a tool which is compatible with the version of the Java Runtime Environment (JRE) which MATLAB is using. You can find the version of the JRE by executing the following command at the MATLAB prompt:
Information on JMP is available here:
Here are the steps to monitor Java VM heap memory using JConsole:
1) You will need to install Oracle's Java Developer Kit (JDK) for the version of the JRE being used by MATLAB. This can be downloaded from
2) Create a java.opts file in the $matlabroot/bin/<arch>
(where $matlabroot is the result of the MATLAB command matlabroot and arch is the system architecture).
3) Add the following lines to the java.opts file
4) Restart MATLAB.
5) Open the JConsole utility from MATLAB
system('"<JDKBIN>\jconsole" <PID> &')
where PID is the process ID for this MATLAB session and can be found from the MATLAB command
and JDKBIN is the bin directory of the JDK installed in step 1. For example the command may look like this
system('"C:\Program Files\Java\jdk1.5.0_07\bin\jconsole" 4296 &')
You should now see the JConsole window and be able to monitor the memory. For example, you should be able to see the effect of forcing Garbage Collection by entering the following command in MATLAB