When a heapdumponoutofmemoryerror occurs, we need to analyze the cause.ProgramSimulate this error and export the dump file for analysis.
Gctest. Java
Package GC; Public Class Gctest { Private Static Final Int _ 1 MB = 1024*1024 ; // About 1 m Public Static Void Main (string [] ARGs ){
// The total size is about 8 MB, and the heap size cannot exceed 8388608b. That is, 8.388608m will cause memory overflow, but an integer is required. If it is less than 8 Mb, this error will be reproduced. Byte [] A1, A2, A3, A4; A1 = New Byte [2 * _ 1 MB]; A2 = New Byte [2 * _ 1 MB]; A3 = New Byte [2 * _ 1 MB]; A4 =New Byte [2 * _ 1 MB] ;}}
This file is on the desktop, So execute the compilation:
Run gctest. BAT:
Set classpath =C: \ Users \ Andy \ Desktop \ GC; Java-Xms10m-xmx10m-xmn2m-XX: Export vorratio = 8-XX: + export-XX: heapdumppath = D: \ gc_study \ log_hprof \ GC. hprof-XX: + printgcdetails-Xloggc: D: \ gc_study \ log_gc \ GC. Log GC. gctestpause
The result is as follows:
GC. hprof File Analysis with memory analysis tools such as mat open (jmap command combined with Mat plug-in analysis Memory leakage) Analysis