Causes and Solutions of memory overflow

Source: Internet
Author: User

Reference: http://baike.baidu.com/view/79183.htm

 

Memory OverflowIt refers to the memory in the application system that cannot be recycled or that is used too much, so that the memory used by the program is greater than the maximum memory available by the virtual machine.

 

Memory OverflowCauseThere are many common types:
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;

 

Memory OverflowSolution:
Step 1Modify the JVM startup parameters to directly increase the memory size. (Do not forget to add the-XMS and-xmx parameters .)

Step 2Check the error log and check whether there are other exceptions or errors before the "outofmemory" error.

 

Step 3To check and analyze the code to find out where memory overflow may occur.

Troubleshoot the following issues:
1. 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.

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

 

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

 

4. 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.

 

5. 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.

 

Step 4, Use the memory viewing tool to dynamically view memory usage.

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.