I. Installing the memory Analyzer Tool
Open Eclipse >> help >> Install New software >> Click the Add on the right side of work, enter
[Name] Mat[location] http://archive.eclipse.org/mat/1.2/update-site/
Click OK >> Click Select All under the Install window, then continue to the next step until the end.
Two. Using Memory Analyzer
Create a Java project (just one Class), Code (class name Oomobject)
1 Importjava.util.ArrayList;2 Importjava.util.List;3 4 /**5 * Created by Foreverenjoy on 16-7-9.6 */7 Public classHeapoom {8 Static classOomobject {9 Ten } One A Public Static voidMain (string[] args) { -list<oomobject> list =NewArraylist<>(); - the while(true) { -List.add (Newoomobject ()); - } - } +}
JAVA Code
To set the VM parameters in debug cofigurations:
-xms20m-xmx20m-xx:+heapdumponoutofmemoryerror
The parameter-xx:+heapdumponoutofmemoryerror allows the virtual machine to dump the current memory heap dump snapshot for post-mortem analysis when a memory overflow exception occurs.
Click Debug to run the project, which will appear
java_pid17179.hprof ... Heap dump file created [27535550 bytes in 0.099 secs]
The java_pid17179.hprof (VM dump snapshot) file can be analyzed using the memory Analyzer tool.
Click File >> Open file >> Select Java_pid17179.hprof (java_*.hprof) Under this Java project >> check leak suspecs report >> F Inish
The following is the analysis of Memory analyzer
Using Memory Analyzer under Linux