Looking deep into the JVM virtual machine book (p50,2.4 combat OutOfMemoryError), there is a Java heap Overflow example, the use of the Eclipse Memory Analyzer plug-in, because they are now using MyEclipse, So you need to add plugins on the MyEclipse. The steps are as follows:
1. Install the mat plugin first
Memory Analyzer Plugin: http://www.eclipse.org/mat/downloads.php
Click to download
3. Extract the downloaded files to the MyEclipse Dropins folder
4. Create a. link file with the same name as the folder, and write the corresponding address in the file (address using \ \ or/)
5. Restart MyEclipse to see the Memory Analyzer option in window---->preferances.
2. Analyze instances using the Mat tool
1. Create test Java code
/**
-verbose:gc-xms20m-xmx20m
-xx:+heapdumponoutofmemoryerror
* @authory **/ Public classTest {Static classoomobject{} Public Static voidMain (string[] args) {List<OOMObject> list =NewArraylist<oomobject>(); while(true) {List.add (Newoomobject ()); } } }
2. Set the operating parameters
Explain the meaning of the parameter:
The 1.JAVA-VERBOSE:GC parameter-VERBOSE:GC represents the detail of the GC in the output virtual machine.
After use, the output is as follows:
[Full GC 168k->97k (1984K), 0.0253873 secs]
Read the following:
Data 168K and 97K before and after the arrows indicate the amount of memory used by all surviving objects before and after garbage collection GC, indicating that the 168k-97k=71k object capacity is recycled, the data in parentheses is 1984K to the total capacity of the heap memory, The time required for collection is 0.0253873 seconds (this time will vary from one execution to the other)
NOTE:GC takes up CPU time slices, which can cause the application to pause at a very short time.
2.-XMS: Sets the minimum value of the heap, –xmx: Sets the maximum value of the heap
They are all set to 20M here, which prevents the heap from automatically expanding.
3. Parameter –xx:+heapdumponoutofmemoryerror allows the virtual machine to dump the current memory heap dump snapshot for post-mortem analysis in the event of a memory overflow exception.
3. Run the program, the following information will appear
At this point, you can find the corresponding file in the project's root directory, then we can use the Mat tool dump out of the heap dump snapshot for analysis.
3. Conduct analysis
1. Open a heap dump snapshot directly via OpenFile
2. Refer to the following link for specific analysis:
http://www.ibm.com/developerworks/cn/opensource/os-cn-ecl-ma/index.html?ca=drs-
http://essen.iteye.com/blog/1825314
http://tivan.iteye.com/blog/1487855
MyEclipse Installing the Eclipse Memory Analyzer plugin and making an error file analysis process