New submission from Tim Peters <[email protected]>:
While people are thinking about gc, zleak.py shows a small bug, and a possible
opportunity for improvement, in the way gc treats finalizers that resurrect
objects.
The bug: the stats keep claiming gc is collecting an enormous number of
objects, but in fact it's not collecting any. Objects in the unreachable set
shouldn't add to the "collected" count unless they _are_ collected.
Output:
resurrecting
collect 2000002
gen 2 stats {'collections': 2, 'collected': 2000002, 'uncollectable': 0}
resurrecting
collect 4000004
gen 2 stats {'collections': 3, 'collected': 6000006, 'uncollectable': 0}
resurrecting
collect 6000006
gen 2 stats {'collections': 4, 'collected': 12000012, 'uncollectable': 0}
resurrecting
collect 8000008
gen 2 stats {'collections': 5, 'collected': 20000020, 'uncollectable': 0}
resurrecting
collect 10000010
gen 2 stats {'collections': 6, 'collected': 30000030, 'uncollectable': 0}
...
Memory use grows without bound, and collections take ever longer.
The opportunity: if any finalizer resurrects anything, gc gives up. But the
process of computing whether anything was resurrected also determines which
initially-trash objects are reachable from the risen dead. Offhand I don't see
why we couldn't proceed collecting what remains trash. Then zleak.py would
reclaim everything instead of nothing.
Sketch: rather than just set a flag, check_garbage() could move now-reachable
objects to the old generation (and, for each one moved, decrement the count of
collected objects). Then delete_garbage() could proceed on what remains in the
unreachable list.
----------
components: Interpreter Core
files: zleak.py
messages: 354020
nosy: nascheme, pitrou, tim.peters
priority: normal
severity: normal
stage: needs patch
status: open
title: finalizer resurrection in gc
type: behavior
versions: Python 3.9
Added file: https://bugs.python.org/file48644/zleak.py
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue38379>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com