Common Java memory overflow exceptions and Solutions

Source: Internet
Author: User
Tags xms

Java memory overflow mainly involves two exceptions: heap memory overflow and non-heap memory overflow.

1. java. lang. OutOfMemoryError: Java heap space. The Heap size setting of JVM Heap refers to the setting of memory space that can be provisioned by JVM during java program running. the JVM automatically sets the Heap size value at startup. The initial space (-Xms) is 1/64 of the physical memory, and the maximum space (-Xmx) is 1/4 of the physical memory. You can use options such as-Xmn-Xms-Xmx provided by JVM to set the configuration. The Heap size is the sum of Young Generation and Tenured Generaion. Tip: if 98% is used for GC and the available Heap size is less than 2% in JVM, this exception is thrown. Tip: the Heap Size should not exceed 80% of the available physical memory. Generally, you must set the-Xms and-Xmx options to be the same to reduce the performance loss caused by the continuous JVM memory expansion, -Xmn is the-Xmx value of 1/4.


Solution: manually set the Heap size,-Xms1024m-Xmx1024m-Xmn256m

2. java. lang. OutOfMemoryError: PermGen space. The full name of PermGen space is Permanent Generation space, which refers to the Permanent storage area of the memory. This memory is mainly used by JVM to store Class and Meta information, when a Class is loaded, it will be placed in the PermGen space. It is different from the Heap region where the Class Instance is stored. GC (Garbage Collection) permGen space is not cleaned up during the main program running period. Therefore, if your application contains many classes, the PermGen space error may occur, this error is common when the web server pre-compile the JSP. If your web app uses a large number of third-party jar files and the size exceeds the default jvm size (4 MB), this error message is generated.

Solution: manually set the MaxPermSize. Add "-XX: MaxPermSize = m" to the Java startup parameters. In the startup parameters, the persistent generation size should not be too large.

Suggestion: Move the same third-party jar files to the common lib directory of the application server to reduce the memory usage of jar files.

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.