Skip to content

Commit 1c3e369

Browse files
committed
OOM
1 parent 6b7ec27 commit 1c3e369

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

MD/OOM-analysis.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# OOM 分析
2+
3+
## Java 堆内存溢出
4+
5+
在 Java 堆中只要不断的创建对象,并且 `GC-Roots` 到对象之间存在引用链这样 `JVM` 就会不会回收对象。只要将`-Xms(最下堆)`,`-Xmx(最大堆)` 设置为一样禁止自动扩展堆内存。
6+
当使用一个 `while(true)` 循环来不断创建对象就会发生 `OutOfMemory`,还可以使用 `-XX:+HeapDumpOutofMemoryErorr` 当发生 OOM 时会自动 dump 堆栈。
7+
8+
伪代码:
9+
10+
```java
11+
public void main(String[] args){
12+
List<String> list = new ArrayList(10) ;
13+
while(true){
14+
list.add("1") ;
15+
}
16+
}
17+
```
18+
19+
当出现 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` 是如何进行关联的,是否存在对象的生命周期过长,或者是这些对象确实改存在的,那就要考虑将堆内存调大了。
20+
21+
22+
## 方法区/运行时常量池溢出

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
### Java 底层
1414
- [Java 运行时内存划分](https://github.com/crossoverJie/Java-Interview/blob/master/MD/MemoryAllocation.md)
1515
- [类加载机制](https://github.com/crossoverJie/Java-Interview/blob/master/MD/ClassLoad.md)
16+
- OOM 分析
1617
- [垃圾回收](https://github.com/crossoverJie/Java-Interview/blob/master/MD/GarbageCollection.md)
1718

1819
### 常用框架

0 commit comments

Comments
 (0)