Exception Handling series: java. lang. OutOfMemoryError: PermGen space, permgen

Source: Internet
Author: User
Tags xms

Exception Handling series: java. lang. OutOfMemoryError: PermGen space, permgen

Today, I helped my colleagues solve the problem of Tomcat startup and reported an OutOfMemoryError. Then I searched and found it very interesting.

The solution is as follows:

The memory is full. So we need to increase the Tomcat memory pool a little.

Modify as follows:
1. window --> Preferences, and then write "tomcat" directly in the search box, the following interface will appear:
 
2. Select the tomcat version you have installed, select the JDK below, and
In the Optional Java VM arguments text box, enter:
-Xmx256M-Xms256M-XX: MaxPermSize = 256 m


Then, click Apply at the bottom, and then click OK.


Below are two simple comments:

First explain what is PermGen space

PermGen space is the Permanent Generation space, which refers to the Permanent storage area of the memory. This part is used to store Class and Meta information. When the Class is loaded, it is placed in the PermGen space area, unlike the Heap region where the Instance is stored, GC (Garbage Collection) does not clean up PermGen space during the main program running, so if your APP loads a lot of classes, the PermGen space error may occur.

Pay attention to the red part. This problem may occur if too many classes are loaded.
Exception: java. lang. OutOfMemoryError: PermGen space

Possible causes include:
Too many classes are loaded.
Too many jar files are loaded.
Too many jar files are loaded repeatedly.

JavalangOutOfMemoryError: PermGen space

Memory overflow.
If your application has 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, the size exceeds the default jvm size (4 MB)
This error message is generated.
Solution: manually set the MaxPermSize
Modify TOMCAT_HOME/bin/catalina. sh
Add the following lines to "echo" Using CATALINA_BASE: $ CATALINA_BASE:
JAVA_OPTS = "-server-XX: PermSize = 64 M-XX: MaxPermSize = 128 m

Suggestion: Move the same third-party jar files to the tomcat/shared/lib directory to reduce the memory usage of jar files.

OrghibernateutilJDBCExceptionReporter-javalangOutOfMemoryError: PermGen space

Java. lang. OutOfMemoryError solution java. lang. OutOfMemoryError Solution

Cause:
The following are common examples:

1. The amount of data loaded in the memory is too large, such as extracting too much data from the database at a time;

2. There are references to objects in the Collection class, which are not cleared after use, so that JVM cannot be recycled;

3. There are endless loops or loops in the code that generate too many repeated object entities;

4. Bugs in third-party software used;

5. The memory value of the startup parameter is set too small;

Common error messages:
1. tomcat: java. lang. OutOfMemoryError: PermGen space

2. tomcat: java. lang. OutOfMemoryError: Java heap space

3. weblogic: Root cause of ServletException java. lang. OutOfMemoryError

4. resin: java. lang. OutOfMemoryError

5. java: java. lang. OutOfMemoryError

Solution;
1. How to Solve the error prompted by the Application Server:
Set the memory value of the startup parameter to large enough.

2. Solutions to errors caused by Java code:
Troubleshoot the following issues:

1) check whether there is an endless loop or recursive call in the code.

2) check whether there are large loops that repeatedly generate new object entities.

3) check whether all data is obtained once in the database query. Generally, if 100,000 records are retrieved to the memory at a time, memory overflow may occur. This problem is relatively hidden. Before going online, the database has less data and is not prone to problems. After going online, there is more data in the database, and a single query may cause memory overflow. Therefore, we recommend that you query the database by page.

4) Check whether List, MAP, and other collection objects are not cleared after use. List, MAP, and other collection objects always have references to objects, so that these objects cannot be recycled by GC.

Case:
1. When hibernate queries data, It queries too much data at a time. Later, it adjusted the code of this Part to retrieve only the specified amount of data at a time, successfully solving this problem.
2. During the stress test, an OutOfMemoryError occurs. It is found that the resources of the session have not been released. It is best to release the resources of the session through the invalidate () method of the session.
3. An endless loop occurs in the program.
4. When an OutOfMemoryError occurs during tomcat deployment and running, increase the memory parameter value to solve this problem.

Java. lang. OutOfMemoryError: Java heap space Exception Handling in tomcat

I. Heap size
The JVM Heap setting refers to the setting of the memory space that JVM can allocate during the 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.
. 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 the same, and-Xmn to the-Xmx value of 1/4.

Ii. Solution: manually set Heap size
Modify TOMCAT_HOME/bin/catalina. sh
In "echo" Using CAT... the remaining full text>

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.