Java中的垃圾收集如何工作? [英] How does Garbage Collection in Java work?

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

问题描述



对象A具有对象B的引用,而对象B具有对象C的引用。

我想知道Java中的垃圾收集器如何处理以下情况。 。
主程序引用了对象A.
因此,您可以使用对象B低谷对象A和对象C低谷对象B低谷对象A.

如果Object A和Object B之间的链接设置为null,那么Object B和Object C会发生什么?



Object B和Object C现在应该如何由垃圾收集器收集?我的意思是在对象B和对象C之间还有一个连接。

解决方案


对象C现在已经被垃圾收集器收集了

是的。那么,它们是收集的候选对象,因为无法通过A的根到达对象B和C.


I was wondering how the garbage collector in Java deals with the following situation.

Object A has a reference to Object B and Object B has a reference to Object C. The main program has a reference to Object A. So you can use Object B trough Object A, and Object C trough Object B trough Object A.

What happens to Object B and Object C, if the link between Object A and Object B is set to null?

Should Object B and Object C now been collected by the Garbage Collector? I mean there is still a connection between Object B and Object C.

解决方案

Should Object B and Object C now been collected by the Garbage Collector?

Yes. Well, they are candidates for collection because there's no way to reach Object B and C through the root that is A.

这篇关于Java中的垃圾收集如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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