Let's say there are following four objects in a Java program:
The dependencies are as follows:
main ==> a ==> b ==> c
In other words, main uses a , a uses b , b uses c .
Now, value of object a changes from reference to b to null . What it means is that there are no active references to b , making it available for garbage collection:
main ==> a =/=> b ==> c
What could happen now:
A) In laymans terms, b can be garbage collected at any time. My assumption is that c will become elligible for gargabe collection only after b is garbage collected.
B) However, I imagine this could be a case that JVM could somehow distinguish between references to c from GC-eligible and non-GC-eligible objects, and therefore mark c as eligible at the same time as b .
Is the behaviour determined by Java Language Specification, or any JVM-related specification? Or is it left for the JVM implementation to decide?
多亏有了此链接,我认为选项B才是正确的: https : //www.dynatrace.com/resources/ebooks/javabook/how-garbage-collection-works/一旦GC根不再可以访问b和c ,它们就可以了两者都可以同时收藏。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.