There are a number of reasons for the memory overflow, and the small series enumerates the following common types:
1. The amount of data loaded in memory is too large, such as to remove too much data from the database;
2. The collection class has a reference to the object, not emptied after use, so that the JVM can not be recycled;
3. Object entities in the code that have dead loops or loops that produce too many duplicates;
4. Bugs in third party software used;
5. Startup parameter memory value set too small
Memory Overflow Solution:
The first step is to modify the JVM startup parameters to increase memory directly. (-XMS,-XMX parameter must not forget to add.) )
In the second step, check the error log to see if there are any other exceptions or errors before the "OutOfMemory" error.
The third step is to check and analyze the code to find out where the memory overflow may occur.
Focus on the following points:
1. Check whether there is a query in the database query that gets all the data. In general, if you take 100,000 records to memory at a time, it can cause a memory overflow. This problem is more covert, before the line, the data in the database is less, not easy to problem, online, the database more data, a query may cause memory overflow. Therefore, the database query as far as possible in the way of paging query.
2. Check to see if there is a dead loop or recursive call in the code.
3. Check if there is a recurring cycle to produce new object entities.
4. Check whether there is a query in the database query that gets all the data. In general, if you take 100,000 records to memory at a time, it can cause a memory overflow. This problem is more covert, before the line, the data in the database is less, not easy to problem, online, the database more data, a query may cause memory overflow. Therefore, the database query as far as possible in the way of paging query.
5. Check the list, map and other collection objects have been used after the problem has not been cleared. Collection objects such as List and map always have references to objects so that they cannot be reclaimed by GC.
Step fourth, use the memory viewing tool to dynamically view memory usage