How does Java solve retain cycles in garbage collection?

后端 未结 4 853
别那么骄傲
别那么骄傲 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条回答
  •  滥情空心
    2021-02-04 07:33

    The garbage collector looks for reachable objects, starting from the roots (typically: variables on the call stack or global variables). So if two objects reference each other but are not otherwise reachable they won't be flagged as "live" and will be collected.

提交回复
热议问题