当前位置:网站首页>如果这题都不会面试官还会继续问我 JVM 嘛:如何判断对象是否可回收
如果这题都不会面试官还会继续问我 JVM 嘛:如何判断对象是否可回收
2022-04-21 16:24:00 【InfoQ】
- 哪些内存需要回收?(GC 目标)
- 什么时候回收?(GC 时间)
- 如何回收?(GC 方法)

引用计数法
objA.instance=objBobjB.instance=objA

可达性分析法
Reachability Analysis
另外,GC Roots 到底存放在哪里呢?
哪些对象的引用可以作为 GC Roots ?



- 判断堆区中的所有对象作为 GC Roots?显然这样作会导致 GC Roots 包含过多对象而过度膨胀
- 只判断新生代中的对象作为 GC Roots?每个内存区域都不是孤立封闭的,所以某个区域里的对象完全有可能被位于堆中其他区域的对象所引用,这时候就需要将这些关联区域的对象也一并加入 GC Roots 集合中去,才能保证可达性分析的正确性。这有个专业术语: 局部回收 (Partial GC),目前最新的几款垃圾收集器无一例外都具备了局部回收的特征,当然它们在实现上也做出了各种优化处理
对象可回收,就一定会被回收吗?
- 如何判断对象是否存活?
- 如何判断对象是否为垃圾?
- 在虚拟机栈中引用的对象
- 在本地方法栈中引用的对象
- 在方法区中类的静态变量引用的对象(JDK 1.7 开始静态变量从方法区移动到了堆中)
- 在方法区中常量引用的对象
- JVM 内部的引用,如基本数据类型对应的 Class 对象,一些常驻的异常对象(比如 NullPointExcepiton、OutOfMemoryError)等,还有系统类加载器等。这个很好理解,毕竟如果这些核心的系统类对象被回收了,程序就没办法运行了
- 所有被同步锁(synchronized 关键字)持有的对象
- ......
版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://xie.infoq.cn/article/98f98b4fbe629f1c9bc703e2a
边栏推荐
- 几种单USB转多串口的方案
- 一文读懂PlatoFarm新经济模型以及生态进展
- C# 滑动验证码|拼图验证|SlideCaptcha
- Qt5. 14.2 compiling MySQL
- 4.25 unlock openharmony technology day! The annual event is about to open!
- OJ每日一练——发放奖金
- 项目中遇到的问题(四) @async的用法及其批量处理大量数据的思路
- Haotian Xuhui signed a contract with Changyang technology to jointly build a new ecosystem of industrial Internet security
- New media people must have 10 efficiency tools and artifact collection
- 【面试普通人VS高手系列】能谈一下CAS机制吗?
猜你喜欢

es6如何判断数组是否重复

CLion 中添加 release 配置

Xiaomi Hongmi's note 4x brush machine succeeded

Invalid bound statement (not found)问题解决

Download the documentation tutorial for free

4.25 unlock openharmony technology day! The annual event is about to open!

SQL--数据库的操作(DDL,DML,DQL)+使用命令查看当前数据库的存储位置(数据库版本查询)
![Buuctf's [actf2020 freshman competition] BackupFile](/img/92/95ba83a3bc8b4ad758097e27c821ce.png)
Buuctf's [actf2020 freshman competition] BackupFile
How many skills are necessary to master automated testing?

Yunna: is the asset management system of large medical equipment expensive? Main contents of hospital asset management
随机推荐
4.25 unlock openharmony technology day! The annual event is about to open!
Detailed explanation of websocket protocol
Online dictionary website
Dating and asynchronous functions
What are the similarities and differences between LCD and OLED screens
What is ram running memory
下载Chrome插件安装到浏览器
小米Civi 1S 定价2299元起,主打美颜,让你上镜自由
Function stack frame creation and destruction (understand)
2022 bone conduction earphone ranking, the best bone conduction earphone recommended
Start redis process
Add release configuration in clion
IOS development interview strategy (KVO, KVC, multithreading, lock, runloop, timer)
Yunna: basic functional features of fixed asset management system in asset intensive enterprises
The conflict between Russia and Ukraine raised concerns. The five eye network security department suggested that allies strengthen infrastructure protection measures
What is the anti correlation principle? How to choose the anti Association fingerprint browser? What are the criteria?
Buuctf's [actf2020 freshman competition] BackupFile
Infrastructure knowledge: DNS command: dig, host
Burp is a simple TP5 rce passive scanning plug-in
Xiaomi civi 1s is priced from 2299 yuan. It focuses on beauty and gives you freedom to appear on the camera