垃圾收集器如何在引擎盖下收集死物? [英] how Garbage collector works under the hood to collect dead object?

查看:50
本文介绍了垃圾收集器如何在引擎盖下收集死物?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读垃圾回收.众所周知,垃圾回收收集死对象并回收内存.我的问题是,收集器如何知道任何对象都死了?它用来跟踪活动对象的数据结构是什么?

I was reading up on garbage collection. As we know, Garbage collection collects dead object and reclaims memory. My question is, how Collector comes to know that any object is dead? what data-structure it use to keep track of live objects?

我正在对此进行研究,我发现GC实际上是跟踪活动对象并对其进行标记.每个未标记的对象均视为已失效.我想,有一个叫做 object-tree 的东西用于此目的.但是我不知道它是如何工作的.

I was researching about this, I found, GC actually keep track of live objects, and marked them. every object that is not marked consider as dead. I guess, there is some thing called object-tree is used for this purpose. but how its works I don't know.

这是我的问题清单.

  • 什么是对象树?
  • 它是如何工作的?当我们使用 new 关键字创建任何对象时,它如何影响该 object-tree ?
  • 谁维护这棵树?jvm,GC,还是这样将对象存储在堆中?
  • what is object-tree?
  • how its works? when we create any object with new keyword, how it affects that object-tree?
  • who maintains this tree? jvm, GC, or that's how objects get stored in heap?

推荐答案

树只是内存堆和对象之间的引用的概念视图.它不作为单独的实体存在.

The tree is just a conceptual view on the memory heap and the references between objects. It does not exist as a separate entity.

由于它可以包含循环,因此它并不是真正的树,因此将其称为图会更准确.在垃圾收集期间,通过遵循引用并跳过那些已经访问过的引用,以树状方式(先遍历或先遍历)对其进行访问.

And it's not really a tree since it can contain cycles, so calling it a graph would be more accurate. During garbage-collection it is visited in a tree-like manner (breadth-first or depth-first traversal) by following references and skipping those already visited.

http://en.wikipedia.org/wiki/Tracing_garbage_collection

这篇关于垃圾收集器如何在引擎盖下收集死物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆