Make iterators hold a reference to the cache - #70
Merged
Conversation
Owner
|
You pointed out a good point. Thanks for the solution. It just seems like there’s a problem |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #69
The iterator types kept a raw cursor and a generation counter, but no reference to the cache object, so a cache that nothing else held was freed while the walk was still running, and the walk read freed memory. Now every iterator type holds a
Py<PyAny>to the cache:keys,valuesanditemstakeslfinstead of&selfand store it.__traverse__is there so the cycle "cache holds the iterator as a value, iterator holds the cache" stays collectable;__clear__is not needed, the cache's own__clear__breaks that cycle.No answers change, and speed does not change either: creating an iterator stays at 37 ns.
Two tests in the shared mixin, so they run for all seven types: walking a cache that nothing else holds, and a cache that holds its own iterator still being collected. The walk runs in a child process on purpose: reading freed memory takes the whole run down instead of failing a test. Without the patch it fails for
CacheandLRUCacheand passes for the other five, which is what reading freed memory looks like.1011 passed, 6 skipped, 5 runs out of 5. Those runs have #68 applied on top: on plain main the suite freezes in almost every run because of #67, which this branch does not touch.