How does Java solve retain cycles in garbage collection?

后端 未结 4 845
别那么骄傲
别那么骄傲 2021-02-04 06:33

I know that a retain cycle (at least in Objective-C and Swift) is when two objects claim ownership of one another (they have references to each other). And in Objective-C we can

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-04 07:24

    In basic terms, Garbage Collection works by walking the object graphs from a number of predefined roots. Anything not accessible from those roots is garbage, therefore one object referencing another is irrelevant unless either can be accessed from one or more roots.

    It's all explained in more detail in How Garbage Collection Really Works.

提交回复
热议问题