Redian新闻
>
Another garbage collection question
avatar
Another garbage collection question# Java - 爪哇娇娃
R*Z
1
In Java, suppose obj A has a reference to obj B, obj B has a reference to obj
C, and obj C has a reference to obj A. And no one else has any reference to
these 3 objs. So each of them has a reference count of 1. But they should
really be GCed because they are not reachable by any means. How does the
garbage collector know these 3 objs can be GCed? Thanks.
avatar
m*t
2

obj
JVM does not use reference counting-based GC. These object would be GC'ed
without any problem.

【在 R***Z 的大作中提到】
: In Java, suppose obj A has a reference to obj B, obj B has a reference to obj
: C, and obj C has a reference to obj A. And no one else has any reference to
: these 3 objs. So each of them has a reference count of 1. But they should
: really be GCed because they are not reachable by any means. How does the
: garbage collector know these 3 objs can be GCed? Thanks.

avatar
g*g
3
http://www.brpreiss.com/books/opus5/html/page424.html
Algorithm like mark and sweep, does the job.
Note Java standard didn't specify how JVM should implement
its recycle scheme.

【在 m******t 的大作中提到】
:
: obj
: JVM does not use reference counting-based GC. These object would be GC'ed
: without any problem.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。