Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11751

Does python garbage collector collects objects with cyclic allocations like below?

$
0
0

Will variable "a" be garbage collected by python garbage collector?

a = [1,2,3]b = [a,a]a.append(b)

If yes, then what happens if we change value of a dynamically? And how does "b" works if the a has been garbage collected? As per my understanding, the reference to a is lost. Does "b" keeps a new copy itself while the initialisation?

I am trying to understand the garbage collection mechanism in python.I read in a blog post that in above code, "a" will get collected by the garbage collector as it is a cycle detection case.


Viewing all articles
Browse latest Browse all 11751

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>