Ronald Oussoren <ronaldousso...@mac.com> added the comment:

I'd expect that there'd be at least one instance of X alive due to 
sys.last_value and in particular sys.last_traceback (which has a reference to 
the stack frame which contains references to local variables).

Btw. I cannot reproduce this with Python 3.9.7 installed with the Python.org 
installer (on MacOS 11):

Python 3.9.7 (v3.9.7:1016ef3790, Aug 30 2021, 16:25:35) 
[Clang 12.0.5 (clang-1205.0.22.11)] on darwin


When I introduce a reference loop the number of X() instances does grow, but 
only until the cyclic garbage collector runs (for example when gc.collect is 
called).

I used slightly tweaked code to investigate:


class Y:
    pass
class X:
    def __init__(self):
        self.y = Y()
        self.y.x = self
    pass

def dump():
    import gc
#    gc.collect()
    objs = gc.get_objects()
    for obj in objs:
        if isinstance(obj, X):
            print(obj)

def f():
    x = X()
    raise Exception()

f()

----------
nosy: +ronaldoussoren

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

Reply via email to