When there is a heapdumponoutofmemoryerror error, we need to analyze the reason, the following program is to simulate this error and export the dump file, so that you analyze
Gctest.java
PackageGC; Public classGctest {Private Static Final int_1mb= 1024 * 1024;//approx. 1m Public Static voidMain (string[] args) {//a total of about 8m, heap size set not more than 8388608B that is 8.388608m memory overflow, but need an integer, less than 8M will reproduce the error byte[] A1, A2, A3, A4; A1=New byte[2 *_1MB]; A2=New byte[2 *_1MB]; A3=New byte[2 *_1MB]; A4=New byte[2 *_1MB]; } }
This file is on the desktop, so do compile:
Execution Gctest.bat:
Set classpath=-xms10m-xmx10m-xmn2m-xx:survivorratio=8-xx:+heapdumponoutofmemoryerror-xx:heapdumppath=d : \study\log_hprof\gc.hprof-xx:+printgcdetails-xloggc:d:\study\log_gc\gc.log GC. Gctestpause
The results are as follows:
Gc.hprof file analysis with memory analysis tools such as Mat open (Jmap command combined with Mat plug-in analysis of memory leaks)
Java Command Exports heap information for memory overflow (heapdumponoutofmemoryerror) (hprof file)