-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
finalizer resurrection in gc #82560
Comments
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 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. |
Just noting that check_garbage() currently only determines which trash objects are now directly reachable from outside. To be usable for the intended purpose, it would need to go on to compute which trash objects are reachable from those too. Maybe a new function static void
deduce_unreachable(PyGC_Head *base, PyGC_Head *unreachable) that packaged the steps through move_unreachable(). The main function would use that on I don't care about the expense. Outside of zleak.py, the number of unreachable objects is usually small, so it's usually cheap to make another pass over just them. |
PR 16658 aims to repair the stats reported. |
I checked the stat fix into master, but GH failed to backport to 3.7 or 3.8 and I'm clueless. More info in the PR. Does someone else here know how to get a backport done? |
Everything here has been addressed, so closing this. zleak.py can apparently run forever now without leaking a byte :-) |
I noticed this bug is mentioned in the 3.9 release notes with a note similar to the title of the 4th PR: "garbage collection does not block on resurrected objects". I can't see any mention of a blocking issue here on the issue:
Would someone be able to elaborate on the blocking issue that was fixed as part of this BPO? |
I suspect you're reading some specific technical meaning into the word "block" that the PR and release note didn't intend by their informal use of the word. But I'm unclear on what technical meaning you have in mind. Before the change, gc "just gave up" after seeing a resurrection, ending the then-current cyclic gc run. It that sense, yes, resurrection "blocked" gc from making progress. It did not, e.g., "block" the interpreter in the sense of deadlock, or of waiting for some lock to be released, or of waiting for a network request to respond, or ... |
You're right that's how I had interpreted it, thanks for clarifying. I was wondering if this could be related to an issue I've hit with gc.collect() getting slower and slower in a test suite, but that now seems unlikely, so I won't go into that here. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: