Skip to content

Commit

Permalink
Update Java 虚拟机.md
Browse files Browse the repository at this point in the history
增加了循环引用的简单分析
  • Loading branch information
PualrDwade authored Mar 21, 2019
1 parent 760ed2e commit 28df184
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/notes/Java 虚拟机.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,15 @@ public class Test {
Test b = new Test();
a.instance = b;
b.instance = a;
a = null;
b = null;
doSomething();
}
}
```

在上述代码中,a与b引用的对象实例互相持有了对象的引用,因此当我们把对a对象与b对象的引用去除之后,由于两个对象还存在互相之间的引用,导致两个Test对象无法被回收。

### 2. 可达性分析算法

以 GC Roots 为起始点进行搜索,可达的对象都是存活的,不可达的对象可被回收。
Expand Down

0 comments on commit 28df184

Please sign in to comment.