Java knowledge learning - heap

The program counter, virtual machine stack, and local method stack that we have learned before all have a common feature, that is, thread private. The heap and local method areas that we understand today are all areas shared by threads.

Heap (Heap), through the new keyword, the objects created will be placed in the heap memory. There are two characteristics: thread sharing, so the objects in the heap need to consider thread safety issues. The local variables in the virtual machine stack mentioned earlier All are thread-private, as long as the local variable does not escape the scope of the method, it is thread-safe. But the heap is different. Objects in the heap need to be considered thread-safe. Another feature is the garbage collection mechanism. Objects that are no longer referenced in the heap will be collected as garbage to release free memory, so that your memory will not be overwhelmed by created objects.

Heap memory overflow problem. Although it is said that the heap has a garbage collection mechanism, it will recycle unreferenced objects as garbage and free up space, but if these objects are constantly created and used all the time, these objects cannot be recycled as garbage. Reaching a certain number of objects will lead to heap memory exhaustion, that is, heap memory overflow. The size of the heap memory can also be set by setting the virtual machine parameters, the parameter is -Xmx.

The diagnosis of heap memory introduces the diagnosis of thread running in the virtual machine stack, and here is also a look at the diagnosis of heap memory.

Jps tool, check which Java processes exist in the current system.

Jmap tool to view the occupancy of heap memory. Can only query a certain moment, heap + process ID.

Jconsole tool, a graphical interface, a multi-functional detection tool, can continuously detect.

Jvisualvm is also more convenient to view heap memory information.

 

Supongo que te gusta

Origin blog.csdn.net/qq_35363507/article/details/104418243
Recomendado
Clasificación