How does Java Garbage Collection work with Circular References?

后端 未结 8 1732
旧时难觅i
旧时难觅i 2020-11-22 04:53

From my understanding, garbage collection in Java cleans up some objects if nothing else is \'pointing\' to that object.

My question is, what happens if we have some

8条回答
  •  旧时难觅i
    2020-11-22 05:26

    Java's GC considers objects "garbage" if they aren't reachable through a chain starting at a garbage collection root, so these objects will be collected. Even though objects may point to each other to form a cycle, they're still garbage if they're cut off from the root.

    See the section on unreachable objects in Appendix A: The Truth About Garbage Collection in Java Platform Performance: Strategies and Tactics for the gory details.

提交回复
热议问题