Skip to content

Commit dacd65b

Browse files
committed
OOM
1 parent b982403 commit dacd65b

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

MD/OOM-analysis.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
伪代码:
99

1010
```java
11-
public void main(String[] args){
12-
List<String> list = new ArrayList(10) ;
13-
while(true){
14-
list.add("1") ;
11+
public static void main(String[] args) {
12+
List<String> list = new ArrayList<>(10) ;
13+
while (true){
14+
list.add("1") ;
15+
}
1516
}
16-
}
1717
```
1818

1919
当出现 OOM 时可以通过工具来分析 `GC-Roots` [引用链](https://github.com/crossoverJie/Java-Interview/blob/master/MD/GarbageCollection.md#%E5%8F%AF%E8%BE%BE%E6%80%A7%E5%88%86%E6%9E%90%E7%AE%97%E6%B3%95) ,查看对象和 `GC-Roots` 是如何进行关联的,是否存在对象的生命周期过长,或者是这些对象确实改存在的,那就要考虑将堆内存调大了。

java_pid26365.hprof

15.1 MB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.crossoverjie.oom;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
/**
7+
* Function:堆内存溢出
8+
*
9+
* @author crossoverJie
10+
* Date: 29/12/2017 18:22
11+
* @since JDK 1.8
12+
*/
13+
public class HeapOOM {
14+
15+
public static void main(String[] args) {
16+
List<String> list = new ArrayList<>(10) ;
17+
while (true){
18+
list.add("1") ;
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)