I would like to investigate the Java Virtual Machine (JVM) memory profile as my MATLAB code is executing.
The best way to monitor is to use jvisualvm which comes with the JAVA JDK and which can attach to MATLAB JVM without any needed changes on the MATLAB side.
An alternative would be to monitor the memory usage of the JVM by using JConsole. Note that this will prevent starting a second MATLAB instance and may lead to problems with the MATLAB Compiler (mcc). 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) Skip this step if using Java 6 or above. Create a java.opts file in the $matlabroot/bin/<arch> directory, where $matlabroot is the result of the MATLAB command matlabroot and <arch> is the system architecture. Add the following lines to the java.opts file
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -XX:+PerfBypassFileSystemCheck
3) Restart MATLAB.
4) 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
Play games and win prizes!Learn more