当前位置:网站首页>jvm-05.垃圾回收
jvm-05.垃圾回收
2022-06-23 04:19:00 【CaptainCats】
垃圾回收
什么是垃圾
jvm中new出来的对象,没有任何引用指向它的时候,它就是垃圾。
垃圾的定位
引用计数
当引用计数变为0的时候就成为垃圾了。
但是,引用计数会没有办法定位循环引用的垃圾对象,
例如,有三个对象互相引用,
但是没有其它外部引用指向它们,它们其实都是垃圾。
垃圾抱起团来也是一堆垃圾(笑cry)。
可达分析
Java采用的是这种方法
将"GC Roots"作为起点,从这些节点开始向下搜索引用的对象,
整条引用链上的对象都被标记为非垃圾,其余未被标记的对象都是垃圾。
GC Roots:线程栈的本地变量、静态变量、本地方法栈的变量等。
垃圾的回收
三种方法
标记清除
标记→然后清除
优点:方法简单,存活对象较多的情况下效率较高,
缺点:两边扫描,效率偏低,也容易产生碎片。
因为回收的这些空间会产生不连续的内存。
拷贝
将空间一分为二,其中一半不用,
回收时将存活的对象整齐拷贝到另一半空间。
优点:没有碎片,
缺点:浪费空间,永远都有一半空间是空闲着的。
标记压缩
标记→然后清除的时候顺带整理好空间
它是消耗时间较长,效率最低的一种,因为边清除边整理。
这三种方法各有特点,实际运用中一般是结合使用。
堆内存分区

年轻代大量死去,少量存活,采用拷贝方法回收,
老年代存活率高,回收较少,采用MS或MC,即标记清除和标记压缩。
伊甸园区的回收会有一个特点,就是经过一次回收后会有大量对象被清除,
回收范围包括伊甸园区和当前的幸存者区,经历过minor GC存活下来的对象,分代年龄会+1,
分代年龄未达到一定值,例如15,会被被拷贝到另外一个幸存者区,否则移动到老年代。
这些情况对象会被放到老年代(对象的分配)


边栏推荐
- Alibaba cloud object storage oss+picgo+typera implements the construction map
- Advanced Mathematics (Seventh Edition) Tongji University exercises 1-8 personal solutions
- Fs2119a Synchronous Boost IC output 3.3V and fs2119b Synchronous Boost IC output 5V
- C primer plus學習筆記 —— 2、常量與格式化IO(輸入/輸出)
- PAT 乙等 1024 科学记数法 C语言
- APP SHA1获取程序 百度地图 高德地图获取SHA1值的简单程序
- runc 符号链接挂载与容器逃逸漏洞预警(CVE-2021-30465)
- MDM数据清洗功能开发说明
- Heimdall database proxy scale out 20 times
- 数字藏品赋能实体产业释放了哪些利好?
猜你喜欢

A bit of knowledge - folding forging and Damascus steel

Advanced Mathematics (Seventh Edition) Tongji University exercises 1-8 personal solutions

知识点滴 - 折叠锻打和大马士革钢

FS2119A同步升压IC输出3.3V和FS2119B同步升压IC输出5V

What is the magic of digital collections? Which reliable teams are currently developing

MySQL面试真题(二十五)——常见的分组比较场景

Real MySQL interview question (23) -- pinduoduo ball game analysis

Analysis on the problems and causes of digital transformation of manufacturing industry

True MySQL interview question (XXII) -- condition screening and grouping screening after table connection

Wechat applet; AI intelligent dubbing assistant
随机推荐
数字藏品火热背后需要强大的技术团队支持 北方技术团队
Differences between fs4059a and fs5080e charging chips
PAT 乙等 1019 C语言
AHA C language Chapter 7 you can do more with it (talks 27-28)
FS4059A与FS5080E充电芯片的区别
Advanced Mathematics (Seventh Edition) Tongji University exercises 1-8 personal solutions
Mobile phone wireless charging dual coil 15W scheme SOC IC ip6809
Arctime makes Chinese and English subtitle video
What does the English letter PC mean? What does the Internet PC mean
高等数学(第七版)同济大学 习题1-8 个人解答
MySQL面试真题(三十)——贝壳-房产订单分析
Yingjixin ip5566 with type-C port 3A charging and discharging fast charging mobile power supply 5W wireless charging in one SOC
MDM data cleaning function development description
C primer plus learning notes - 2. Constant and formatted IO (input / output)
技能自检 | 想当测试Leader,这6项技能你会吗?
PAT 乙等 1015 C语言
Real MySQL interview questions (XXVI) -- didi 2020 written examination questions
Pit filling for abandoned openssl-1.0.2 (.A to.So)
Genetic engineering of AI art? Use # artbreeder to change any shape of the image
Wechat applet: wechat can also send flash photos to create wechat applet source code download and customize flash time