Depth understanding of JAVA virtual machine study notes (b)

2.4.1 Java Heap Overflow

Java heap is used to store an object instance, as long as we continue to create objects, and ensure GC Roots between objects reachable path to avoid the garbage collection to remove these objects, with the increase in the number of objects, the total capacity to reach the largest heap it will have the capacity limit of memory overflow exception.
Java heap memory of an OutOfMemoryError is the practical application of the most common memory overflow exceptions. When the advent of Java heap memory overflow exception stack information "java.lang.OutOfMemoryError" will follow further you suggest that "Java heap space".
To resolve exceptions, conventional treatment methods this memory area is to first analyze the heap dump snapshot Dump out by the memory image analysis tools (such as Eclipse MemoryAnalyzer). The first step should first confirm whether the memory leads to OOM objects is necessary, that is, in the end must first make it clear that there is a memory leak (Memory Leak) or memory overflow (Memory Overflow).
If it is a memory leak , you can check the leak object through the tool to the GC Roots reference chain, find leaking objects are by what reference path, which GC Roots associated with, which leads to the garbage collector can not reclaim them, the type according to the leak object and its specific location information to the reference information GC Roots chains, generally can more accurately locate the position of these objects are created, and then find out the code memory leaks.
If it is not a memory leak , in other words, the object in memory really is a must to survive, it should check the parameters of the Java Virtual Machine heap (-Xmx and -Xms) settings, memory compared with the machine to see if there are upward adjustment of space. From then on the code checks for the presence of certain object life cycle is too long, too long held status, storage unreasonable structure design, etc., to minimize memory consumption run the program.

Released eight original articles · won praise 2 · Views 209

Guess you like

Origin blog.csdn.net/qq_37492314/article/details/105331296