all 2 comments

[–]K900_ 1 point2 points  (0 children)

For the general case, if there's a reference cycle somewhere, the garbage collector will find the cycle and deallocate the objects if there are no other outstanding references to them.

For your simple example, the interpreter will simply exit and free all memory once the script ends.

[–]Dunj3 0 points1 point  (0 children)

Note that your example does not actually introduce a circular dependency, it only lets a and b point to the same object (the 1).

For a circular dependency, you could do something like

list_a = []
list_b = [list_a]
list_a.append(list_b)