8000 Add section about the design of CPython's garbage collector by pablogsal · Pull Request #562 · python/devguide · GitHub
[go: up one dir, main page]

Skip to content
8000

Add section about the design of CPython's garbage collector #562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jan 21, 2020
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
10ee4fd
Add section about the design of CPython's garbage collector
pablogsal Jan 20, 2020
8aac485
Fix several typos
pablogsal Jan 20, 2020
7776e14
Update garbage_collector.rst
pablogsal Jan 20, 2020
c72ce11
Fix more typos
pablogsal Jan 20, 2020
410487b
Update garbage_collector.rst
pablogsal Jan 20, 2020
b18da79
Update garbage_collector.rst
pablogsal Jan 20, 2020
25d7555
Apply suggestions from code review
pablogsal Jan 20, 2020
811235f
Fix more typos
pablogsal Jan 20, 2020
8b72c71
Update garbage_collector.rst
pablogsal Jan 20, 2020
3b84282
Update garbage_collector.rst
pablogsal Jan 20, 2020
0d3f322
Apply suggestions from code review
pablogsal Jan 21, 2020
d84a267
Apply suggestions from code review
pablogsal Jan 21, 2020
5ca46f7
Fix indentation and rework incomplete sentence
pablogsal Jan 21, 2020
404fcc5
Fix more indentation
pablogsal Jan 21, 2020
8fc0547
Rework sentence about _gc_prev
pablogsal Jan 21, 2020
e956478
Update garbage_collector.rst
pablogsal Jan 21, 2020
47190cd
Fix indentation
pablogsal Jan 21, 2020
722a99c
Fix quotes
pablogsal Jan 21, 2020
b40b030
Fix typo and indentation
pablogsal Jan 21, 2020
111b2bb
Update garbage_collector.rst
pablogsal Jan 21, 2020
2ec5002
Update garbage_collector.rst
pablogsal Jan 21, 2020
7c8e02a
Add author section
pablogsal Jan 21, 2020
e51d354
Add a warning section regarding tagged pointers
pablogsal Jan 21, 2020
411037f
Add reference to the memory layout
pablogsal Jan 21, 2020
4081607
Fix link to the generation section
pablogsal Jan 21, 2020
03178a0
Apply suggestions from code review
pablogsal Jan 21, 2020
6d01e46
Fix more typos
pablogsal Jan 21, 2020
4321593
Address Petr feedback and fix more typos
pablogsal Jan 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix more typos
  • Loading branch information
pablogsal committed Jan 20, 2020
commit c72ce11f9acf333581c584aa4e97ca135470a22b
16 changes: 8 additions & 8 deletions garbage_collector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ the interpreter create cycles everywhere. Some notable examples:
* When representing data structures like graphs is very typical for them to
have internal links to themselves.

To correctly dispose of these objects once they become unreachable, they need to
be identified first. This is done in the `deduce_unreachable() <https://github.com/python/cpython/blob/6202d856d637a9b4eb9789b4d4a1edb12d877de5/Modules/gcmodule.c#L1089>`__
function. Inside this component, two double-linked lists are maintained: one list contains
all objects to be scanned, and the other will contain all objects "tentatively" unreachable.
To correctly dispose of these objects once they become unreachable, they need to be
identified first. Inside the function that identifies cycles, two double-linked
lists are maintained: one list contains all objects to be scanned, and the other will
contain all objects "tentatively" unreachable.

To understand how the algorithm works, Let’s take the case of a circular linked list which has
one link referenced by a variable A, and one self-referencing object which is completely
unreachable
To understand how the algorithm works, Let’s take the case of a circular linked list
which has one link referenced by a variable A, and one self-referencing object which
is completely unreachable

.. code-block:: python

Expand Down Expand Up @@ -202,7 +202,7 @@ to ``link 2`` and ``link 3`` below as they are reachable from ``link 1``. From
state in the previous image and after examining the objects referred to by ``link1``
the GC knows that ``link 3`` is reachable after all, so it is moved back to the
original list and its ``gc_refs`` field is set to one so if the GC visits it again, it
does not that is reachable. To avoid visiting a object twice, the GC marks all
does know that is reachable. To avoid visiting a object twice, the GC marks all
objects that are not visited yet with and once an object is processed is unmarked so
the GC does not process it twice.

Expand Down
0