Increase the heap space of the Java VM in MATLAB (solve the outofmemory problem that Xml_io_tools appears)

Source: Internet
Author: User
Tags java se

Today, using MATLAB to write a program, called the Xml_io_tools (a great XML read-write toolkit) in the function, but because I want to write the file is larger, about 5m, the runtime does not know which piece of xml_io_tools in the Java memory limit, So to study how to increase the Java VM in the Matlab heap space, first use English in the wall outside search for half a day, Google search out of the first few are using Jconsole to allocate space, but need to download the corresponding version of Matlab JDK, the middle of various twists and turns, see the end of the text, Finally gave up the treatment in Chinese search, found that there has been an official answer, Khan, the article copied over it

Http://www.mathworks.cn/matlabcentral/answers/131276-matlab-6-0-r12-java-vm

This feature is already included in the 2010A (r2010a) version. For versions after MATLAB 7.10 (r2010a), you can change this setting using the Preferences dialog box. For more information, see "Java Heap Memory Preferences" on the documentation page (Java heap memories Preferences). You can access it as follows:

1. Open the Help browser by typing the following command at the MATLAB command prompt:

Doc

2. Search the Search bar of this document browser for "Java Heap Memory Preferences" (Java Heap Memories Preferences).

For previous versions, see the instructions given below on how to increase the Java heap space memory.

Starting with MATLAB 6.0 (R12), you can use the following files to increase the heap space for a Java virtual machine (VM):

Java.opts

1. Create the Java.opts file:

Create a text file named Java.opts in the $MATLABROOT/bin/$ARCH directory. $MATLABROOT is the MATLAB root directory, $ARCH is your system architecture and can be found by typing the following command at the MATLAB command prompt:

Matlabrootcomputer (' Arch ')

If you do not have write access to the $MATLABROOT/bin/$ARCH, or if you want to have a user-specific version, you can create a java.opts file in the MATLAB startup directory. You can find the MATLAB startup directory by executing the following command at the MATLAB command prompt (before executing any MATLAB code):

Pwd

If you are using MATLAB 7.7 (r2008b) or later on a MAC OS system, the MATLAB default installation directory is

/applications/matlab_< version >.app

where,< version > is the version of MATLAB, namely r2008b, r2009a and so on. To access the contents of the/applications/matlab_< version >.app directory, in the Finder, navigate to applications (applications) and right-click matlab_< version >.app. Click Show Package Contents, and you'll see the contents of the catalog.

2. Determine the Java virtual machine (JVM) version you are using:

The content of java.opts depends on your JVM version. To determine the version of the JVM that you are running, type the following command at the MATLAB command prompt:

Version-java

Note: If you perform these actions in MATLAB 7.5 (r2007b), read this error report:

3. Determine the value to write to the java.opts file:

When MATLAB starts, it launches the Java runtime environment. MATLAB uses a set of default values as the initial and maximum heap space (managed by the heap manager). When the available memory approaches zero, Java dynamically increases the heap space until the max heap size setting is reached. The following table shows the default settings for the JVM version of MATLAB:

JVM     initial heap size           max heap Size
1.6.0    -xms64m              -xmx128m (32-bit)                               -xmx196m (64-bit) 1.5.0    -xms64m              -xmx96m (32-bit)                               -xmx128m (64-bit) 1.4.2    -xms16m              -xmx96m 1.3.1    -xms16000000         -xmx64000000 1.2.2    -xms16000000         -xmx64000000 1.1.8    -ms16000000          -mx64000000

You can use the following command to obtain information about the use of Java heap space in MATLAB:

Java.lang.Runtime.getRuntime.maxMemoryjava.lang.Runtime.getRuntime.totalMemoryjava.lang.Runtime.getRuntime.freeMemory

Here I insert a sentence: For my version (1.6,64bit), as long as the java.opts write-xmx196m, he allocated 196m of memory, if it is-xmx512m, allocated 512m memory, You can use Java.lang.Runtime.getRuntime.maxMemory to see if the assignment is successful or not. (Note that you want to restart MATLAB When you are finished saving)

Users can override them by manually setting these values in the Java.opts file. For example, include the following line in the Java.opts file to set the maximum heap size value to zero MB:

For JVM 1.2.2 and later versions, add the following to the Java.opts file:

-xmx256m

For JVM 1.1.8, add the following to the Java.opts file:

-mx256m

This will provide you with a memory of up to MB of the JVM, which you can adjust as needed. Keep in mind that increasing the size of the Java heap may reduce the amount of available space in the MATLAB array accordingly. For more information, see the following guidelines for memory management:

4. Troubleshooting:

In some cases, Java memory problems can be caused by increasing the Java heap size and exceeding a certain limit. See this solution for more information:

If you increase the Java heap size in response to "Outofmemoryerror:java heap space", but you still receive the same error message when you increase it, there may be a memory leak, or you may retain a reference to a Java object that is out of its usefulness. The Java SE Troubleshooting guide may help you isolate the problem:

http://java.sun.com/javase/6/webnotes/trouble/

To kill a routine:

1, download JDK1.6 a variety of under

2, install a higher version of MATLAB (2012B), found the same Java version

3, try to modify MATLAB so that it supports java1.7 above version (real dead)

4, when I was dying, I searched in Chinese. Matlab Java heap Space is insufficient, the result steady

Increase the heap space of the Java VM in MATLAB (solve the outofmemory problem that Xml_io_tools appears)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.