JAVA Heap Settings

Source: Internet
Author: User

JAVA Heap Settings Section Fourth

The heap has already been talked about, and this chapter gives us an example of how to set up and how to troubleshoot problems when a heap overflow occurs. Let's look at a short piece of code:


The code uses an infinite loop to add an object to the list, and if it takes a default heap size it may take a long time to get a heap overflow error, so let's set it a little bit smaller:

Setting methods in-xms10m-xmx10m-xx:+heapdumponoutofmemoryerror,elipse we talked about it in the first chapter, and we don't say much here. -xms10m, meaning that the minimum heap memory is 10m. Similarly-xmx10m means that the maximum memory is 10m. Both are set to 10m, so the heap size is 10m. And-xx:+heapdumponoutofmemoryerror refers to the memory overflow when the current memory usage will be generated a snapshot save, but need eclipse download a mat plug-in, download the way the Niang everywhere.

Start the program with the parameters you just set, and the following error will occur if you wait a little bit:


The heap overflow error is displayed, and a file called Java_pid4792.hprof is generated, and we can refresh the project to see the file, double-click to open it, and take a period of loading time.


The first thing you can see is a pie chart, and the most occupied part is the part where the overflow error occurs, and then we look down:

Here we look at the part of the red line, here are some of the surviving large objects, in the overflow when the general suspicion of large objects, we point in:


Here are some of the most memory-intensive objects, and it is clear that the first one is suspicious, with a occupancy rate of 94.64%! Continue to follow up:

The discovery is a test object, so you can do this when troubleshooting. Then we right-click the object to select Path to GC Root (the path on the reference chain), and then select Exclue all Phantom/weak/soft etc. Reference, results


You can see that he is referenced by the list, so he has been referencing the chain, causing it to not be recycled, and there is a memory overflow.

This article only speaks of one of the most basic uses of mat, pointing out the troubleshooting ideas, interested in the small partners can combine the work of the case himself in-depth to understand its more uses.

About the settings of the various areas in the heap first not here, step by step, and so the road is clear, the problem will be solved!

JAVA Heap Settings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.