Use the command to view memory usage
After analyzing a Java heap dump file using jhat, you can view the most memory-consuming class in the web page it provides.
Specific steps
Start the jhat command and analyze the heap dump file:
jhat -J-Xmx4g
The above command will start a web server and load the heap dump file.
Open http://localhost:7000 in your browser and access jhat's web page.
On the page, you will see some links, one of which is "Object Histogram". Click this link.
The "Object Histogram" page lists statistics for all objects, including class names, number of instances, and memory size.
By default, objects are arranged in descending order of memory size, that is, the objects that consume the most memory are ranked first.
Find the class that occupies the most memory in the list and click on the class name. You will see detailed information about the class, including the number of instances, the size of memory, and other objects it references.
Through the above steps
You can view the most memory-consuming class and its details in the web page provided by jhat.
If you want to analyze memory leaks or other memory problems more deeply, you can use more professional Java heap analysis tools such as Eclipse Memory Analyzer (MAT) or VisualVM.
These tools provide more features and options to help you better understand the distribution of objects in the Java heap.
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.