In the following code, the object named a is an attribute of itself, which creates a reference cycle.
class MyClass(object):
pass
a = MyClass()
a.obj = a
If I were to then call del a, I supposedly would not have gotten rid of all the references to a, since the self-referencing nature of a is supposed to prevent it from having a non-zero reference count.
I'm not sure why it has to be the case that reference cycles prevent the reference count from going to 0. Could someone explain this to me, step-by-step?
a.objis a reference toa. Any way you count that, the reference count isn't 0..aattribute. If you diddel a.obj; del athen there would be no more references to the objectdelremoves names, it doesn't affect objects at all. if I hada = object(); b = a; del athenbis still referring to the same object, and it hasn't been affected at all bydel a(aside from it's internal reference count being lowered by 1)del ajust unassigns a variable. It doesn't do anything to the object the variable used to refer to.