File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change
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
+ ## 方法区/运行时常量池溢出
Original file line number Diff line number Diff line change 13
13
### Java 底层
14
14
- [ Java 运行时内存划分] ( https://github.com/crossoverJie/Java-Interview/blob/master/MD/MemoryAllocation.md )
15
15
- [ 类加载机制] ( https://github.com/crossoverJie/Java-Interview/blob/master/MD/ClassLoad.md )
16
+ - OOM 分析
16
17
- [ 垃圾回收] ( https://github.com/crossoverJie/Java-Interview/blob/master/MD/GarbageCollection.md )
17
18
18
19
### 常用框架
You can’t perform that action at this time.
0 commit comments