Skip to content

Commit ffeb81f

Browse files
committed
Update comment
1 parent 3350121 commit ffeb81f

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎Python/gc.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,8 +2168,10 @@ visit_generation(gcvisitobjects_t callback, void *arg, struct gc_generation *gen
21682168
PyGC_Head seen;
21692169
int res = 1;
21702170

2171-
/* The callback may free or untrack the object it is given, so always
2172-
* take the first object and move it to `seen` before calling it. */
2171+
/* Iterate directly on the gc head to ensure the iteration is safe
2172+
* from a callback freeing its object (which can also cause
2173+
* a cascading free). Visited objects are moved to `seen` and
2174+
* merged back at the end. */
21732175
gc_list_init(&seen);
21742176
while (res && !gc_list_is_empty(gc_list)) {
21752177
PyGC_Head *gc = GC_NEXT(gc_list);

0 commit comments

Comments
 (0)