看Thinking in Java碰到的关于Java 垃圾回收机制引发的问题.

最近在看Thinking in Java, 读到How a garbage collector works 这一节的时候有这么几句话不太理解 (前面讲到一种简单但是很慢的垃圾回收的方法是reference counnting)

The garbage collector moves through the entire list of objects, and
when it finds one with a reference count of zero it releases that
storage (however, reference counting schemes often release an object
as soon as the count goes to zero). The one drawback is that if
objects circularly refer to each other they can have nonzero reference
counts while still being garbage.

这是原文, 我不能理解的是为什么出现循环引用的时候他会出现仍然进行垃圾收集,因为循环引用的时候不应该是两个object的counter都到不了0才对嘛,按照正常逻辑这两个object出现的问题应该是永远也不会被垃圾回收,而按照作者的意思恰好相反.

阅读 2.4k
1 个回答

The one drawback

一个缺点是……

我没有看到意思正好相反啊

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题