Skip to content

Commit

Permalink
OOM
Browse files Browse the repository at this point in the history
  • Loading branch information
crossoverJie committed Dec 29, 2017
1 parent b982403 commit dacd65b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
10 changes: 5 additions & 5 deletions MD/OOM-analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
伪代码:

```java
public void main(String[] args){
List<String> list = new ArrayList(10) ;
while(true){
list.add("1") ;
public static void main(String[] args) {
List<String> list = new ArrayList<>(10) ;
while (true){
list.add("1") ;
}
}
}
```

当出现 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` 是如何进行关联的,是否存在对象的生命周期过长,或者是这些对象确实改存在的,那就要考虑将堆内存调大了。
Expand Down
Binary file added java_pid26365.hprof
Binary file not shown.
21 changes: 21 additions & 0 deletions src/main/java/com/crossoverjie/oom/HeapOOM.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.crossoverjie.oom;

import java.util.ArrayList;
import java.util.List;

/**
* Function:堆内存溢出
*
* @author crossoverJie
* Date: 29/12/2017 18:22
* @since JDK 1.8
*/
public class HeapOOM {

public static void main(String[] args) {
List<String> list = new ArrayList<>(10) ;
while (true){
list.add("1") ;
}
}
}

0 comments on commit dacd65b

Please sign in to comment.