当Java垃圾收集器的访问路径断开时,如何处理循环引用? [英] How does Java garbage collector deals with circular references when their access path is broken?

查看:70
本文介绍了当Java垃圾收集器的访问路径断开时,如何处理循环引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想向我解释一下,当引用计数大于0但实际上不可访问时,GC如何发现那些内存块(以红色区域显示)是垃圾?

I just want someone explain it to me that how does GC discover that those memory blocks (pictured in red area) are garbage when their reference count is more that 0 but they are practically inaccessible?

推荐答案

有一组根对象"被认为始终可以访问:例如,线程引用,静态变量,类引用.如果无法通过来自这些根对象的引用链接来访问某个对象,则即使存在对该对象的某些引用,也认为该对象可用于GC.

There's set of "root objects" which are considered always accessible: e.g., Thread references, static variables, class references. If some object can not be reached via link of references from these root objects, it considered to be available for GC, even if there are some references to that object.

这篇关于当Java垃圾收集器的访问路径断开时,如何处理循环引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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