Why does python use both reference counting and mark-and-sweep for gc?

后端 未结 3 986
谎友^
谎友^ 2020-12-03 01:22

My question is why does python use both reference counting and mark-and-sweep for gc? Why not only mark-and-sweep?

My initial guess is that using reference counting

3条回答
  •  萌比男神i
    2020-12-03 02:12

    Reference counting deallocates objects sooner than garbage collection.

    But as reference counting can't handle reference cycles between unreachable objects, Python uses a garbage collector (really just a cycle collector) to collect those cycles when they exist.

提交回复
热议问题