What does cpython do to help detect object loops (reference counting)?

From what I read about cpython, it looks like it refers to a count + something extra to detect / free objects pointing to each other (correct me if I am wrong). Can someone explain something else? Does this also guarantee * no cycle? If there is no research of any algorithm that could be added to the reference count so that it never leaks *? Would it just run a link count trace without a link so often?

* discounting errors and problems with modules using the interface of external functions

+3
source share
1 answer

As explained in the documentation for gc.garbage, there is no guarantee that leaks will not occur; in particular, cyclic objects with methods are __del__not collected by default. For such objects, cyclic links must be broken manually to enable an additional GC.

From what I understand, looking at the code of the CPython code , the interpreter keeps links to all objects under its control. An "additional" garbage collector runs the algorithm with a label and a sweep through the heap, remembers for each object if it is accessible from the "outside" and, if not, deletes it. (GC generational , but it can be explicitly started from a module gcwith an argument generation.)

, , , "" GC , , , , Python. , .

+4

Source: https://habr.com/ru/post/1766615/


All Articles