简体   繁体   English

了解Java中的垃圾收集器

[英]Understanding garbage collector in java

I'm trying to understand the Concurrent mark and sweep GC algorithm. 我正在尝试了解并发标记和扫描GC算法。 I'm reading the following explanation : 我正在阅读以下说明 在此处输入图片说明

QUESTION: So what does the sweep actually mean? 问题:那么扫描实际上是什么意思? Is it the actual garbage collection (reclaiming unreachable object and freeing memory?)? 它是实际的垃圾回收(回收无法访问的对象并释放内存吗?)? Or it means something different? 还是意味着不同?

If so, what kind of troubles we can run into if we omit the sweep phase ? 如果是这样,如果省略扫描阶段会遇到什么麻烦?

In the linked explanation the "sweep" step is actually not described. 在链接的说明中,实际上没有描述“扫描”步骤。

Roughly speeking: 大致窥视:

  1. mark : find the "root" object(s), and perform a traversal of the object graph, marking all objects, which are touched during the traversal. mark :找到“根”对象,然后遍历对象图, 标记遍历过程中接触过的所有对象。
  2. sweep : go through your heap from A to Z and delete all objects which aren't marked ( sweep through your heap; or sweep the non-marked objects from your heap). 扫描 :从A到Z遍历您的堆,并删除所有未标记的对象( 扫描您的堆;或从堆中清除未标记的对象)。

If you don't do sweep the memory is not freed, just marked as free (think of the "Trash bin" in your OS -> mark = put into trash bin; sweep = delete from trash bin). 如果您不执行清除操作,则不会释放内存,只是将其标记为空闲(例如,操作系统中的“垃圾箱”->标记=放入垃圾箱;清除=从垃圾箱中删除)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM