OOM解决方案
-verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+HeapDumpOnOutOfMemoryError
内存映像分析工具(例如eclipse memory analyzer)堆dump出来的堆转储快照进行分析,重点是确认内存中的对象是否是必要的.
也就是要先分清楚到底是出现了内存泄漏(memory leak)还是内存溢出(memory overflow)
注意项目名称不要有下划线,不然会报错说找不到主类.
[GC (Allocation Failure) 7727K->5313K(19456K), 0.0102958 secs]
[GC (Allocation Failure) – 13505K->19416K(19456K), 0.0150072 secs]
[Full GC (Ergonomics) 19416K->10071K(19456K), 0.1473511 secs]
[Full GC (Ergonomics) 17568K->15873K(19456K), 0.1319149 secs]
[Full GC (Allocation Failure) 15873K->15869K(19456K), 0.0746161 secs]
java.lang.OutOfMemoryError: Java heap space
Dumping heap to java_pid27392.hprof …
Heap dump file created [27960490 bytes in 0.080 secs]
Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.util.Arrays.copyOf(Unknown Source)
at java.util.ArrayList.grow(Unknown Source)
at java.util.ArrayList.ensureExplicitCapacity(Unknown Source)
at java.util.ArrayList.ensureCapacityInternal(Unknown Source)
at java.util.ArrayList.add(Unknown Source)
at HeapOOM.main(HeapOOM.java:14)
-verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=D:\dump.hprof
[GC (Allocation Failure) 7626K->5249K(19456K), 0.0075257 secs]
[GC (Allocation Failure) 13441K->11134K(19456K), 0.0121616 secs]
[Full GC (Ergonomics) 11134K->11066K(19456K), 0.1505298 secs]
[Full GC (Ergonomics) 18562K->16355K(19456K), 0.1338673 secs]
[Full GC (Allocation Failure) 16355K->16343K(19456K), 0.0911646 secs]
java.lang.OutOfMemoryError: Java heap space
Dumping heap to D:\dump …
Heap dump file created [27960542 bytes in 0.452 secs]
Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.util.Arrays.copyOf(Unknown Source)
at java.util.ArrayList.grow(Unknown Source)
at java.util.ArrayList.ensureExplicitCapacity(Unknown Source)
at java.util.ArrayList.ensureCapacityInternal(Unknown Source)
at java.util.ArrayList.add(Unknown Source)
at HeapOOM.main(HeapOOM.java:14)
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [util.c:840]