Introduction
Memory management has always been a proud and proud capital of the Java language, allowing Java programmers to fundamentally ignore the details associated with memory management and focus only on business logic. But there is no perfect good in the world, bringing convenience at the same time, it has introduced a lot of maddening memory overflow and leakage problems.
The scary thing is not only that, some programmers who have developed in other languages have put a "memory-less" hat on Java programmers, which is a bit hard to accept. After all, there is no malloc and delete in Java, no destructors, no pointers, how can the programmers who just started to touch Java possibly touch the memory part, let alone a lot of Java programmer still jump professional halfway decent friend.
But although the facts are difficult to accept, but it does have a lot of Java programmer memory This part is not known, although the knowledge of memory, perhaps not to the normal development of the changes and benefits, but it will still imperceptibly improve your technical level, this point after understanding the memory management, I believe you will have a deep understanding.
Memory Partitioning
When it comes to memory, it is a data storage area only when the program is running, and for this area, each virtual machine has its own way of partitioning, but they all have to conform to the Java Virtual machine's basic specifications.
In the virtual machine specification, memory is divided into six parts, namely, PC registers, Java Virtual machine stacks, Java heaps, method areas, run-time pools, and local method stacks.
Java Virtual machine specification and Java Virtual machine
Here you also need to explain the difference between Java Virtual machine specifications and Java virtual machines, as the name implies, Java Virtual Machine specification is a Java Virtual machine implementation of the specification requirements, is made by Oracle, And we usually say that Java virtual machines generally refers to a specific Java Virtual Machine specification implementation. For example, our most commonly used Java Virtual machine hotspot, in fact, there are many Java Virtual machine implementation, even if you have a deep understanding of Java Virtual Machine specifications and interested in it, you can write a Java virtual machine, of course, this is not difficult to imagine the difficulty.
Structure diagram
The diagram below is a structure diagram of a JVM referenced in Baidu Library, which does not run a regular pool because it is an area allocated by the method area.