Deleting Python object reference (reference counting)

I know when Python handles object, it uses ‘reference’ to the object, not the real value itself.

But behavior of below code seems very odd to me.
5 dummy object references were copied from prev to now list, then prev was cleared.

Then, shouldn’t references stored in now be invalidated too?

class dummy:

prev = [dummy() for _ in range(5)] 

now = []
for d in prev:

for idx in range(5):
    print(prev[idx] is now[idx]) # all True - so, same reference copied

print(prev) # empty
print(now) # 5 'dummy' objects survived - How??

I found possible duplicate to this question, and would like to ask if this is the reason why references in now isn’t invalidated after prev.clear()
Python: Delete object referenced from tuple

Maybe I’m too used to reference concept in C++ and Python is different.


By adding each object in prev to now, you increment their reference counts by 1, so they become 2.

When you delete the objects in prev, reference count of each object is decremented by 1, and they become 1.

Since reference counts of the objects did not reach 0, they do not go away.