安裝
直接安裝或者在idea插件安裝
GC Roots溯源
- 代碼
/**
* @describe: GCRootsTest
* @author: zhuCw
* @date: 2020/11/24 18:30
*/
public class GCRootsTest {
public static void main(String[] args) {
List<Object> numList = new ArrayList<>();
Date birth = new Date();
for (int i = 0; i < 100; i++) {
numList.add(String.valueOf(i));
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("數據添加完畢,請操作:");
new Scanner(System.in).next();
numList = null;
birth = null;
System.out.println("numList、birth已置空,請操作:");
new Scanner(System.in).next();
System.out.println("結束");
}
}
- 使用idea 的jprofile運行該代碼
- 實時內存-> 所有對象可以查看所有內存的實時情況
- 視圖->標記當前值 可以查看動態變化
- 運行GC 可以直接執行GC操作
- 選中要分析的對象,右鍵 show selection in heap walker
- 點擊引用
- 傳入引用 選中對象 右鍵 -> 顯示到GC的路徑進行GC溯源
幫助文檔
https://www.ej-technologies.com/resources/jprofiler/help/doc/main/introduction.html