Tag Archives: Differences and connections

The difference, cause and solution of memory overflow and memory leak

memory overflow and memory leak are two different problems, but they are closely related to heap.

Mainly about the JVM memory structure and how to use the scheme.

Memory overflow?Possible causes of memory overflow?Memory overflow solutions, memory leak small series of recommendations for you

Memory overflow?Common memory overflow?The solution of memory overflow

memory overflow:

when you apply for 2 bytes, if you use the int type and occupy 4 bytes, there will be memory overflow in this case

possible reasons for memory overflow: 1

1. The amount of data loaded in the memory is too large, such as fetching too much data from the database at one time;
2. There are references to objects in the collection class, which are not cleared after use, so that the JVM cannot recycle;
3. There are dead loops in the code or too many duplicate object entities generated by loops;
4. Bugs in the third-party software used;
5. The memory value of the startup parameter is set too small

solution to memory overflow:

The first step is to modify the JVM startup parameters to increase the memory directly. (- XMS, – Xmx parameters must not be added. )

Second, check the error log to see if there are other exceptions or errors before the “OUTOFMEMORY” error. (check the next error log)

The third step is to walk through and analyze the code to find out the possible location of memory overflow. (Debug)

The fourth step is to use the memory view tool to dynamically view the memory usage

Memory leak

there are too many static modified variables defined in the project, but these variables are in the permanent area, which may not be recycled regularly by GC. With the accumulation, memory leakage will occur when applying for memory next time.

Suggestions for you

We must not define too many variables in the development process, because the variables modified by static all exist in the permanent area. You can understand the details

JVM memory structure

learn in actual combat and grow in happiness