Brandt Bucher <brandtbuc...@gmail.com> added the comment:

> I added some comments in the PR regarding the possibility of forcing the 
> tracking on the visiting function

Thinking about this more, I'm a bit hesitant to put the re-tracking code in the 
traverse function (mostly stemming from my lack of knowledge about our GC 
algorithm). I have no idea how problematic tracking and untracking objects 
*during* collections can be. Consider the following reference chain:

-> z -> r -> o -> r

Here, z is a zip iterator, r is its result tuple, and o is some object. Let's 
say r was untracked in the previous collection (I believe untrack_tuples 
happens *after* all of the traverse functions are called).

I'm worried that the GC may not be able to detect the cycle if it visits o, 
then z (which *then* starts tracking r), then r.

Or, if this group is determined to be unreachable, untrack_tuples untracks r 
*before* the cycle is cleaned up. That seems like it could be a problem.

Or, if z's refcount drops to zero and it's cleaned up, its traverse function 
may *never* be called, which leaves the untracked r -> o -> r cycle.

I guess I'm just not sure how resilient the GC is to these sorts of things. 
Re-tracking the result tuple in __next__ sidesteps all of these potential 
issues, with no significant performance impact. So I think I might slightly 
prefer that.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42536>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to