Is there any practical usage of using reference cycling?
On Sat, 2016-09-03 at 14:56 +0100, Alan Gauld via Tutor wrote: > On 03/09/16 04:25, monik...@netzero.net wrote: > > > > > Is this what you mean? > > a = 5 > > b = a > > a = b > > No, you are confusing variable names with objects. > Here you only have one object - the number 5. > For a cycle you need at least 2 objects and those > objects must be able to reference another object. > In practice that means a collection or an instance > of a class. > > a = [] > b = [a] > a.append(b) > > The two lists are now cyclically referring to each > other. We can now delete the names a and b and > the two list objects will continue to exist > in memory even though no variables refer to them. > This is where the second garbage collector comes > into play, it can recognise the link between the > lists and the fact that no variable refers to them. > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor