Here is a example of a cyclic reference of Python.
>>> a = [1]
>>> b = [2]
>>> a.append(b)
>>> b.append(a)
after this,
>>> sys.getrefcount(a) = 3
>>> sys.getrefcount(b) = 3
Why do a
and b
have a reference count of 3??
Sorry guys i just took a mistake.
the real question is the different one.
>>> GNU = ['is not Unix']
>>> GNU.insert(0, GNU)
>>> sys.getrefcount(GNU) = 4
Why is the reference count of 'GNU' is 4 ?
Thanks in advance :)
There are 3 references to each:
sys.getrefcount()
.a
and b
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With