Reasons to distinguish OOM

In order to solve OOM, the common method is to analyze the dump heap dump snapshot through the Memory image analysis tool. The main point is to confirm whether the object in Memory is necessary, and to clarify whether there is a Memory Leak or Memory Overflow.

A memory leak

In the event of a memory leak, the tool can further look at the chain of references from the leaking object to GC Roots to find out what path the leaking object is associated with GC Roots, so that the GC cannot automatically collect them.

Out of memory

If there is no memory leaks, then really should also have to live in the memory, it should check the pile of parameters of the virtual machine (-xmx and – Xms), compared with the physical memory of the machine, look to whether can also big, check whether there is from the code, some of the life cycle is too long, the state of continuous time is too long object, reducing application runtime memory loss.